PrintCenter with font 0 and a string over 254 characters.
Displaying 1-7 of 7 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Overkill

Hey, neat. I discovered that Verge will crash if it tries to PrintCenter a string that is larger than 254 characters. I crashes every time, with every string over the maximum length. It however does not express this problem for PrintString or PrintRight of font 0, nor does it crash when you use a font other than 0. Just thought I'd let you guys know. I can't quite figure out what's causing it from a glance at vid_sysfont.cpp

Posted on 2005-12-28 18:06:46

Overkill

Actually on second thought, yes I can. I've changed the following...


void PrintCenter(int x1, int y1, char *str, image *dest, ...)
{
va_list argptr;
char msg[256];

va_start(argptr,dest);
vsprintf(msg,str,argptr);
va_end(argptr);
str=msg;

GotoXY(x1 - pixels(str)/2, y1);
PrintString(str, dest);
}

...to this:

void PrintCenter(int x1, int y1, char *str, image *dest, ...)
{
GotoXY(x1 - pixels(str)/2, y1);
PrintString(str, dest);
}

Posted on 2005-12-28 18:09:25

Jesse

What about all the ... args that you're now ignoring? Are they never used?

Posted on 2005-12-29 07:38:13

Overkill

No, it didn't use the ... args. PrintRight() already didn't use the arguments, it was just a GotoXY() and PrintString(), so I'm assuming that they aren't necessary. Plus, if you'll notice, it assigns msg[256] to str (even though str can be larger than 256 chars), but then further on, assigns str to msg which is fairly redundant.

Posted on 2005-12-29 11:25:55 (last edited on 2005-12-29 11:33:07)

Kildorf

Er... that wasn't useless garbage though. The ... and va_* etc. stuff means that it could take in-string variable replacements like printf().

Of course, if it never got used (which I imagine it didn't, since the VC PrintCenter() doesn't have any such parameters (and, with easy string concatenation, it doesn't need them)) then it's probably not necessary to have them in there.

Posted on 2005-12-29 11:30:39

vecna

It should probably be fixed correctly though, the font system can be used direcly from C The C api should work correctly as well as the VC api... I mean, if the "VC debugger" is ever implemented, it will use those very same font routines and they should work as expected.

Posted on 2005-12-29 17:09:32

aen

On the topic of fixing this correctly, I believe there are MSDN examples that illustrate how to do so with the secure versions of vsprintf, etc. There is a method which returns exactly how many characters will be needed to accommodate the final representation, etc.

The provided examples allocate and free a buffer of the necessary size within each call to whatever method is performing the variable argument handling. I'm not sure whether this would be acceptable in V3 or not, as custom rendering loops are going to be calling multiple PrintStrings or whatever string rendering methods, which ultimately end up calling these methods with variable argument handling. Allocating and unallocating tons of tiny chunks of memory every frame is probably not a Good Idea.

At any rate, I'd leave that to testing to determine first. If it did turn out to be an issue, my vote would be for a global stack of dynamically growing buffers. Maybe a stack of STL strings would work, I don't know. Each buffer on the stack would only grow as necessary, and the stack would allow for recursive calls or calls chaining between a few separate methods which all happen to make use of variable argument management. This would be the ideal "no limits" solution.

Perhaps a much easier route would simply be to make these local internal buffers 4K or 8K or some other ridiculously large value that is unlikely to be exhausted for 99% of string manipulations. Detection for exhaustion would still need to be present, and exhaustion would simply cause truncation of the result. Not an ideal no limits solution, but a pretty practical one that would require a whole helluva lot less code and time to test.

Posted on 2005-12-31 15:01:50


Displaying 1-7 of 7 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.