• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Is there anything wrong with doing the following in C?

SunnyD

Belgian Waffler
sprintf(stringptr, "%s", stringptr);

I know it appears redundant, however I'm using it in the context of a reparser/string builder... so there's a method to my madness. It "works", however I'm worried that under certain contexts it might blow up. I suppose I would really need to know how sprintf really works internally to answer that.
 
I don't think you'll have any problems. I can imagine scenarios where that might cause an issue, but I can't imagine sprintf behaving in a way that makes any of those scenarios possible. The easiest one to envision would be if the formatting takes place in a loop that reads and then writes one character at a time, and an input character generates >1 output characters (i.e. the write pointer gets ahead of the read pointer). Don't see it happening here.
 
Originally posted by: Markbnj
I don't think you'll have any problems. I can imagine scenarios where that might cause an issue, but I can't imagine sprintf behaving in a way that makes any of those scenarios possible. The easiest one to envision would be if the formatting takes place in a loop that reads and then writes one character at a time, and an input character generates >1 output characters (i.e. the write pointer gets ahead of the read pointer). Don't see it happening here.

In my implementation, that doesn't happen. I have a source string, and the destination string is always at least as big as the source string. What's happening is that in the loop that scans each character out of the source, if it encounters a character that needs to be escaped it then goes and reallocates a wider buffer for the destination string (wide enough for the original string + the number of characters that are being added from the escaping).

I finished it up, knocked out the bugs, and everything looks like it's working. I just wanted to make sure I wasn't going to have any nasty surprises from sprintf in this case.
 
Back
Top