Bug 11778 – format for null does not verify fmt flags.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-19T12:42:00Z
Last change time
2014-04-07T03:44:06Z
Keywords
pull
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-12-19T12:42:54Z
Printing pointer types is supposed to only work with %X, %x or %s. However, if the passed pointer is null, there is no actual fmt validation: //---- import std.stdio; void main() { int* p; writefln(s, p); writefln(s, p + 1); } //---- null std.format.FormatException@std/format.d(2957): Expected one of %s, %x or %X for pointer type. //---- This can be an issue, as an invalid format flag may end up throwing depending on the *value* passed (and not the type). The bug may only reveal itself unexpectedly at a later date.
Comment #1 by andrej.mitrovich — 2013-12-20T06:39:59Z
Where is 's' defined?
Comment #2 by andrej.mitrovich — 2013-12-20T06:41:48Z
I guess this could be a test-case: ----- import std.stdio; void main() { string s = "%d"; int* p; writefln(s, p); // does not throw writefln(s, p + 1); } -----
Comment #3 by monarchdodra — 2013-12-20T07:34:20Z
(In reply to comment #1) > Where is 's' defined? Hum... I forgot to copy paste it. Much apologies. I had defined it as: enum s = "%d" (In reply to comment #2) > I guess this could be a test-case: > > ----- > import std.stdio; > void main() > { > string s = "%d"; > int* p; > writefln(s, p); // does not throw > writefln(s, p + 1); > } > ----- Yes, exactly.
Comment #4 by k.hara.pg — 2014-04-03T04:51:24Z
Comment #5 by github-bugzilla — 2014-04-03T08:01:42Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/b32e4032c1adbdabd4cdcfe3599606d806762038 fix Issue 11778 - format for null does not verify fmt flags. https://github.com/D-Programming-Language/phobos/commit/f8288c7ea321cfee94561f70a64fc01f81c7ae10 Merge pull request #2069 from 9rnsr/fix11778 Issue 11778 - format for null does not verify fmt flags.