[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#635126: Standalone test case



Hi,

Attached is a standalone test case for this bug, obtained on an 
up-to-date sid/sparc system. With it I see the following behavior:

jurij@debian:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/sparc-linux-gnu/4.6/lto-wrapper
Target: sparc-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --enable-targets=all --with-long-double-128 --enable-checking=release --build=sparc-linux-gnu --host=sparc-linux-gnu --target=sparc-linux-gnu
Thread model: posix
gcc version 4.6.2 (Debian 4.6.2-5) 
jurij@debian:~$ 
jurij@debian:~$ gcc -g -O2 -fno-tree-sra pack.c -o pack
jurij@debian:~$ ./pack
do_something called with item=-32767
do_something called with item=-123456
jurij@debian:~$ 
jurij@debian:~$ gcc -g -O2 pack.c -o pack
jurij@debian:~$ ./pack
do_something called with item=-32767
Bus error
jurij@debian:~$ 
jurij@debian:~$ gdb pack
GNU gdb (GDB) 7.3-debian
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "sparc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jurij/pack...done.
(gdb) run
Starting program: /home/jurij/pack 
do_something called with item=-32767

Program received signal SIGBUS, Bus error.
pack_unpack (s=0x1068a "\377\376\035\300", p=0x10692 "") at pack.c:62
62			memcpy (v.a, s, sizeof (int32_t));
(gdb) bt
#0  pack_unpack (s=0x1068a "\377\376\035\300", p=0x10692 "") at pack.c:62
#1  0xf7e64854 in __libc_start_main () from /lib/sparc-linux-gnu/libc.so.6
#2  0x00010378 in _start ()
(gdb) 

I don't believe that it's related to the upstream bug Lucas mentioned, 
as it was specifically triggered by using bit fields, which are not 
used in any way here.

Best regards,
-- 
Jurij Smakov                                           jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC
#include <string.h>
#include <stdio.h>
#include <stdint.h>

void
do_something (int item)
{
  printf ("do_something called with item=%d\n", item);
}

void do_something (int item) __attribute__ ((noinline));

int
pack_unpack (char *s, char *p)
{
  char *send, *pend;
  char type;
  int integer_size;

  send = s + strlen (s);
  pend = p + strlen (p);

  while (p < pend)
    {
      type = *p++;

      switch (type)
	{
	case 's':
	  integer_size = 2;
	  goto unpack_integer;

	case 'l':
	  integer_size = 4;
	  goto unpack_integer;

	unpack_integer:
	  switch (integer_size)
	    {
	    case 2:
	      {
		union
		{
		  int16_t i;
		  char a[sizeof (int16_t)];
		}
		v;
		memcpy (v.a, s, sizeof (int16_t));
		s += sizeof (int16_t);
		do_something (v.i);
	      }
	      break;

	    case 4:
	      {
		union
		{
		  int32_t i;
		  char a[sizeof (int32_t)];
		}
		v;
		memcpy (v.a, s, sizeof (int32_t));
		s += sizeof (int32_t);
		do_something (v.i);
	      }
	      break;
	    }
	  break;
	}
    }
  return (int) *s;
}

int
main ()
{
  return pack_unpack ("\200\001\377\376\035\300", "sl");
}

Reply to: