-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Steven M. Schweda wrote:
>>From <various>:
> 
>> [...]
>>    char filecopy[2048];
>>    if (file[0] != '"') {
>>      sprintf(filecopy, "\"%.2047s\"", file);
>>    } else {
>>      strncpy(filecopy, file, 2047);
>>    }
>> [...]
>> It should be:
>>
>>      sprintf(filecopy, "\"%.2045s\"", file);
>> [...]
> 
>    I'll admit to being old and grumpy, but am I the only one who
> shudders when one small code segment contains "2048", "2047", and "2045"
> as separate, independent literal constants, instead of using a macro, or
> "sizeof", or something which would let the next fellow change one buffer
> size in one place, instead of hunting all over the code looking for
> every "20xx" which might be related?

Well, as already mentioned, aprintf() would be much more appropriate, as
it elminates the need for constants like these.

And yes, "magic numbers" drive me crazy, too. Of course, when used with
printf's 's' specifier, it needs special handling (crafting a STR()
macro or somesuch).

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGjxcX7M8hyUobTrERCHSAAJ9VkQdfhK4/LwByseYH2ZYVzoPqPwCePU1k
2Llybpq/oceXWMyZpBO4bPY=
=Vj/R
-----END PGP SIGNATURE-----

Reply via email to