Hello, all. I recently found what I believe to be a bug in Allegro. Please view the example with code in the Allegro.cc forums:
http://www.allegro.cc/forums/view_thread.php?_id=377919
(My username may show as "Gideon Weems")
Earlier today, I may have solved the problem, but because I have never done anything of this nature, I'll try to recollect for you the debug process. Along the way, I gained a firm grasp of how each function worked with the others, so I'm fairly certain that I've remedied the error. All you boys and girls can read along at home, if you like!
I started in text.c with textprintf(), which led to uvszprintf() in unicode.c, where I eventually determined that decode_format_string() may be returning a faulty value to len (line 2955). In decode_format_string(), the switch block's case 'n' (line 2818) was obviously a prime suspect. However, one can quickly see that there's no problem: The argument corresponding to the %n (accessed through pstr_pos) is given the running length of the string (len), and the length of the produced decoded string (slen) is set to 0, as it should be. Then, the next character is retrieved, and the switch block is broken. However, immediately after the switch block, the string produced from the format specifier (string_arg) is examined--and this is where the problem occurs. Looking at line 2869, one can see the condition statement for an if block that works with string_arg. At this point, you can stop thinking because the problem is clear: the code in the conditional block thinks that string_arg is a string, but string_arg shouldn't even exist because there is no string that goes along with assigning a pointer a value with the %n specifier. Besides, one can obviously see that its length is 0 (line 2822), soooo I proudly present to you perhaps the smallest bug fix ever. On the conditional block of line 2869 in unicode.c...
Change the ">=" to a ">"
Thank you, ladies and gentlemen. I'm very proud of my work; is that how it's done? Attached is a diff file for Allegro v4.03 stable release. Please feel free to comment, and I thank you for your time.
-Grady
P.S. I guess I'm the only one who ever used %n!
--- unicode.c.old 2003-04-19 09:06:48.000000000 +0000
+++ unicode.c 2004-06-27 13:25:14.000000000 +0000
@@ -2866,7 +2866,7 @@
break;
}
- if (slen >= 0) {
+ if (slen > 0) {
if (slen < info.field_width) {
if (info.flags & SPRINT_FLAG_LEFT_JUSTIFY) {
/* left align the result */