GifDrawBoxedText8x8() modifying constant input parameter
A library and utilities for processing GIFs
Brought to you by:
abadger1999,
esr
Hello Eric.
I think that this:
Might not be the best way to fix the problem.
First, it is not clear why use malloc() + strcpy() instead of strdup()?
Second, should the image be modified at all if this allocation fails? I personally think it should not for at least two reasons:
Why waste time on drawing the rectangle if the text rendering is going to fail?
If the text rendering is going to fail that means the legend string is malformed in which case you will surely crash in GifDrawRectangle() since it does no checking of TextWidth (w) and LineCount (d) against actual image width and height.
Also, it would be more readable if you use early exit and write:
/ compute size of text to box /
+
+
Instead of wrapping a large piece of code in an if () block, increasing the indent for it.
Finally, in my opinion legend parameter should be passed along with its length to this function, and you should not rely on it being properly terminated. That most definitely requires either an API change or silently discarding stuff which to me seems even worse.
Regards,
Igor Levicki
igor@levicki.net
Sorry for the very belated response, it's been a busy year.
Igor Levicki igor-levicki@users.sf.net:
Because this code runs on some extremely ancient and crufty systems that
might not have strdup(3)!
You are right. I have moved code accordingly.