Skip to content

Commit 3ed36ab

Browse files
committedOct 1, 2024·
Fix wind_get(WF_NAME)
Some AES like MagiC return a pointer to the name instead of copying the string
1 parent 398838c commit 3ed36ab

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed
 

‎a_wind_get.c

+78-2
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ mt_wind_get (short WindowHandle, short What,
318318
aes_intout[AES_INTOUTMAX];
319319
long aes_addrin[AES_ADDRINMAX],
320320
aes_addrout[AES_ADDROUTMAX];
321+
short namebuf[64];
321322
AESPB aes_params;
322323

323324
aes_params.control = &aes_control[0]; /* AES Control Array */
@@ -337,11 +338,16 @@ mt_wind_get (short WindowHandle, short What,
337338
case WF_DCOLOR:
338339
case WF_COLOR:
339340
aes_intin[2] = *W1;
341+
/* older versions of XaAES expect the element in intout[1] */
342+
aes_intout[1] = *W1;
343+
/* AES 4.1/N.AES do not return the 3d flags */
344+
aes_intout[4] = 0x0f0f;
340345
*(ptr ++) = 3; /* aes_control[1] */
341346
break;
342347
case WF_INFO:
343348
case WF_NAME:
344-
aes_intin_ptr(2, short *) = W1;
349+
aes_intin_ptr(2, short *) = namebuf;
350+
namebuf[0] = -1;
345351
*(ptr ++) = 4; /* aes_control[1] */
346352
break;
347353
default:
@@ -355,12 +361,82 @@ mt_wind_get (short WindowHandle, short What,
355361
/* ol: this line is required for WF_FIRSTXYWH and WF_NEXTXYWH because
356362
lot of programmers doesn't verify the return value and espect W or H
357363
will be 0 it's not true for NAES */
364+
aes_intout[0] = 0;
365+
aes_intout[1] = aes_intout[2] = -1;
358366
aes_intout[3] = aes_intout[4] = 0;
359367

360368
AES_TRAP(aes_params);
361369

362370
if (What == WF_INFO || What == WF_NAME) {
363-
/* special case where W1 shall not be overwritten */
371+
/*
372+
* we want to behave like documented above (copying the string to
373+
* where the first parameter points to), however things are a bit
374+
* more complicated:
375+
* - XaAES will already do that, if nintin is 4
376+
* - N.AES will do that regardless of nintin
377+
* - MagiC does not return the string, but instead its address in intout[1/2]
378+
* There are applications that expect MagiC's behaviour,
379+
* so we must handle all cases.
380+
*/
381+
char *name;
382+
char *dst;
383+
384+
name = aes_intout_ptr(1, char *);
385+
if (name != (char *)-1)
386+
{
387+
/* name was returned as address (MagiC) */
388+
if (W2 != NULL && W2 == (W1 + 1))
389+
{
390+
/* application passed two pointers, to get the address as hi/lo */
391+
*W1 = aes_intout[1];
392+
*W2 = aes_intout[2];
393+
} else
394+
{
395+
/* application passed only one pointer */
396+
if (name == 0)
397+
{
398+
dst = (char *)W1;
399+
if (dst != NULL)
400+
{
401+
if (name == NULL)
402+
{
403+
*dst = '\0';
404+
} else
405+
{
406+
while ((*dst++ = *name++) != '\0')
407+
;
408+
}
409+
}
410+
}
411+
}
412+
} else if (namebuf[0] != -1)
413+
{
414+
/* name was written to buffer */
415+
if (W2 != NULL && W2 == (W1 + 1))
416+
{
417+
/* application passed two pointers, to get the address */
418+
/* no way to support this, since we only have the string */
419+
*W1 = 0;
420+
*W2 = 0;
421+
aes_intout[0] = 0;
422+
} else
423+
{
424+
/* application passed only one pointer */
425+
name = (char *)namebuf;
426+
dst = (char *)W1;
427+
if (dst != NULL)
428+
{
429+
while ((*dst++ = *name++) != '\0')
430+
;
431+
}
432+
}
433+
} else
434+
{
435+
/*
436+
* nothing was returned?
437+
* hopefully return code will indicate error
438+
*/
439+
}
364440
} else {
365441
#if CHECK_NULLPTR
366442
if (W1) *W1 = aes_intout[1];

‎a_wind_get_int.c

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ mt_wind_get_int (short WindowHandle, short What, short *W1, short *global_aes)
3939
case WF_DCOLOR:
4040
case WF_COLOR:
4141
aes_intin[2] = *W1;
42+
/* older versions of XaAES expect the element in intout[1] */
43+
aes_intout[1] = *W1;
44+
/* AES 4.1/N.AES do not return the 3d flags */
45+
aes_intout[4] = 0x0f0f;
4246
*(ptr ++) = 3; /* aes_control[1] */
4347
break;
4448
default:
@@ -58,6 +62,7 @@ mt_wind_get_int (short WindowHandle, short What, short *W1, short *global_aes)
5862

5963
if (What == WF_INFO || What == WF_NAME) {
6064
/* special case where W1 shall not be overwritten */
65+
/* actually should not get here; use wind_get() instead */
6166
} else {
6267
#if CHECK_NULLPTR
6368
if (W1) *W1 = aes_intout[1];

0 commit comments

Comments
 (0)
Please sign in to comment.