|
|
|
|
|
by WalterBright
3211 days ago
|
|
From the link: "That means that we have been going through the tree cleaning out all calls to sprintf(), strcpy(), and strcat(). Instead, these things are being rewritten to use asprintf(), snprintf(), strlcpy(), and strlcat()." Maybe the author made a typo. |
|
Another thing I've done that will work if you have a lot of strcat(), is make a string struct:
It keeps track of the string's actual length, and the size of the underlying buffer. Then you can 'override' the various string functions: These functions will take care of buffer-size checking, and reallocation if necessary. For cases where you need to interface with pre-existing libraries, you can return a cstring(). Make it a function/macro to enable you to change the struct definition in the future: then you can pass it into write() or whatever you need: