sizeof computes size in bytes. swprintf's second arg is a number of wide characters.
-
-
-
Yep. But look how easy it is to overlook or even write the long thing.
-
From a usable security standpoint, an API that /looks just like/ one where sizeof works, but where it's wrong, is utterly awful.
-
Functions like swprintf probably should have taken a buffer size, not a [wchar_t/whatever] count.
-
That makes it harder to access the last-written location.
-
I don't follow. The return value would still be a wchar_t count.
-
Er, in that case it means I can't subtract it from the buffer size.
-
If I were to change something here, it would be sizeof, which does the "wrong" thing for pointers too.
- 5 more replies
New conversation -
-
-
sizeof can be avoided by using a named constant for the length
-
That's much worse. It creates an obligation to keep multiple things consistent, and it's not genericizable.
-
what do you mean? enum { length = 123 }; …
-
Now you need a convention for naming the length of each buffer object/struct-field, a way to namespace them, ...
-
...and if you accidentally mix up which goes with which, you have buffer overflows. snprintf(buf, sizeof buf, ...) is always ok.
-
ok, the constant works only for local arrays. The other obvious improvement over sizeof is an ARRAY_LENGTH macro.
-
Yes,
#define countof(arr) (sizeof(arr)/sizeof(*arr)) -
But when ppl have to remember to use a countof rather than a sizeof, you have a security UX problem for programmers.
- 2 more replies
New conversation -
-
-
The real bug isn't the missing division but rather using wide character stdio instead of sticking to only using UTF-8.
-
That's kinda the point, but seeing the hard bug is strongly illustrative of the point.
End of conversation
New conversation -
-
-
Format string not wide?
-
Yeah I screwed up the tweet; that's not the point. Pretend it was L"%s/%d".
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.