Re: [AD] xmessage broken pipe

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Peter Wang wrote:
I thought of a slight problem with this approach. If the message is "-print", "-center" or "-nearmouse" (and perhaps other options in future) then xmessage will think it is an option argument. A workaround is to put an extra space at the end of the message string (say, after the uconvert) before passing it to xmessage.

This patch fixes allegro_message itself to make this impossible to happen. The Allegro docs neglect to mention whether or not you need a trailing \n character, even though when it prints to the console you'll get improper lining without it (printing a string without the trailing \n and then quitting, for example, will cause the shell prompt to append to the very end of the printed message). And because of the prevalence of Windows and now X using xmessage, it might not be apparent that you'd need it.

The patch also fixes a problem with the two mallocs not being checked for success.
Index: src/allegro.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/allegro.c,v
retrieving revision 1.46
diff -b -u -r1.46 allegro.c
--- src/allegro.c	4 Dec 2004 12:59:50 -0000	1.46
+++ src/allegro.c	11 Dec 2004 01:31:43 -0000
@@ -430,16 +430,28 @@
    char *buf = malloc(ALLEGRO_MESSAGE_SIZE);
    char *tmp = malloc(ALLEGRO_MESSAGE_SIZE);
    va_list ap;
+   int len;
+
    ASSERT(msg);
+
+   if ((buf == NULL) || (tmp == NULL))
+      goto quit;
+
    va_start(ap, msg);
-   uvszprintf(buf, ALLEGRO_MESSAGE_SIZE, msg, ap);
+   len = uvszprintf(buf, ALLEGRO_MESSAGE_SIZE, msg, ap);
    va_end(ap);
 
+   if ((ugetc(buf+len-ucwidth('\n')) != '\n') && (len < ALLEGRO_MESSAGE_SIZE-ucwidth('\n')-ucwidth('\0'))) {
+      usetc(buf+len, '\n');
+      usetc(buf+len+ucwidth('\n'), '\0');
+   }
+
    if ((system_driver) && (system_driver->message))
       system_driver->message(buf);
    else
       fputs(uconvert(buf, U_CURRENT, tmp, U_ASCII_CP, ALLEGRO_MESSAGE_SIZE), stdout);
 
+quit:
    free(buf);
    free(tmp);
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/