This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Could you help me out?
- To: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- Subject: Could you help me out?
- From: Ken Tan <ken at pythonvideo dot com>
- Date: Wed, 6 Oct 1999 17:26:10 -0400
- Cc: "'bug-gcc at gnu dot org'" <bug-gcc at gnu dot org>
Dear Sir/Madam,
I am facing a problem described as followed, could you tell me how to fix it?
I am not sure whether or not it is bug.
Thanks in advance,
Ken Tan
1)
`gcc -- version` = 2.95
`g++ -- version` = 2.95
System type = Solaris 7 / SPARC
2)
Source code is follwed as below named (e.g. test.cc)
Compiling command `gcc test.cc` or `g++ test.cc`
The core is dumped when a.out is running "sum += *(unsigned int*)(ptr + i) ;"
The runing on Linux/X86 is OK.
3)
Source code:
/* srouce code starting ....
The core is dumped when the sentence "sum += *(unsigned int*)(ptr + i) ;" of
this program is excuting.
But it is ok when the sentence "sum += *(unsigned int*)(ptr + i / 4 * 4) ;" of
this program is excuting.
Is this a bug for g++/gcc version 2.95 / Solaris 7 / SPARC ?
Or should I use some options in the compiler command line?
**/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
int main(int argc, char* argv[])
{
char* ptr ;
unsigned int len ;
unsigned int i ;
unsigned int sum ;
if(argc != 2){
printf("Usage: %s argument.\n", argv[0]) ;
return -1 ;
} ;
if((ptr = (char*) malloc(len = strlen(argv[1]) * 8)) == (char*)NULL){
printf("Not enough virtual memory\n") ;
return -1 ;
} ;
memset(ptr, (int)NULL, len) ;
strcpy(ptr, argv[1]) ;
sum = 0 ;
for(i = 0 ; i < strlen(ptr) - sizeof(unsigned int) + 1 ; i ++){
printf("(%u)before plus sum\n", i) ;
# if defined(ALIGN)
sum += *(unsigned int*)(ptr + i / 4 * 4) ;/* OK */
# else
sum += *(unsigned int*)(ptr + i) ; /* Bus Error - core dumped */
# endif
printf("(%u)after plus sum\n", i) ;
} ;
return 0 ;
}
/* source code end. */