Re: [AD] xmessage broken pipe |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: Re: [AD] xmessage broken pipe
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Fri, 10 Dec 2004 17:30:03 -0800
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:return-path:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:references:in-reply-to:x-enigmail-version:x-enigmail-supports:content-type; b=As/W/L3+XgoGqKkh2rLzqqY4hMlT6dOANNqWZJ+jW/idaM3Vh8D2PJkXkUNoBgiEDRwD10LdWnGVMK0smnAEP+jyNa9wTRCrluA9tZ3xp3dxLykhPs4Q+Wxac7/yW2Nb1Kc94Zrg+WRcjSvdCpwpH24eLk2A/hBQv3lJMHhATDw=
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);
}