🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Lupe Christoph Thu, 06 Aug 1992 16:17
va-sparc.h bug
#284
Author: Lupe Christoph
Date: Thu, 06 Aug 1992 16:17
49 lines
2450 bytes
As I don't save all the bug reports going by, I don't know if this has already
been reported.

Anyway, here is a bug report and a fix.

Both gcc and g++ use the same architecture-dependend include file for
<stdarg.h>. In my case, va-sparc.h. This file contains the SPARC
definition of va_arg(pvar,TYPE).

The definition gives wrong results if sizeof (TYPE) < sizeof (int);
The part that does the argument fetch dereferences the starting
address of the argument with a *(TYPE*). This is correct for large
arguments (>= sizeof (int)). For a small argument, it works correctly
only on a little endian architecture. SPARC isn't.

I have fixed this by testing for small argument types and dereferencing
the pointer as an int *, *then* casting to TYPE. This should work on
all architectures, big or little endian, but I'm currently only interested
in SPARC.

Attached is a context diff with the entire macro.


*** va-sparc.h.orig	Sun Jun 21 11:41:38 1992
--- va-sparc.h	Thu Aug  6 14:05:49 1992
***************
*** 51,64 ****
--- 51,66 ----
  #define va_arg(pvar,TYPE)					\
  __extension__							\
  ({ TYPE __va_temp;						\
     ((__builtin_classify_type (__va_temp) >= 12)			\
      ? ((pvar) += __va_rounded_size (TYPE *),			\
         **(TYPE **) ((pvar) - __va_rounded_size (TYPE *)))	\
      : __va_rounded_size (TYPE) == 8				\
      ? ({ union {TYPE d; int i[2];} u;				\
  	 u.i[0] = ((int *) (pvar))[0];				\
  	 u.i[1] = ((int *) (pvar))[1];				\
  	 (pvar) += 8;						\
  	 u.d; })						\
      : ((pvar) += __va_rounded_size (TYPE),			\
+        (sizeof (TYPE) < sizeof (int)) ?                         \
+        (TYPE) *((int *) ((pvar) - __va_rounded_size (TYPE))) :  \
         *((TYPE *) ((pvar) - __va_rounded_size (TYPE)))));})

| ...!unido!ukw!lupe  (German EUNet, "bang")     |  Disclaimer:            |
| lupe@ukw.UUCP       (German EUNet, domain)     |  As I am self-employed, |
| suninfo!alanya!lupe (Sun Germany)              |  this *is* the opinion  |
| Res non sunt complicanda praeter necessitatem. |  of my employer.        |
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads