This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/32166] Condition check for const char string fails
- From: "kmanjunat at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 1 Jun 2007 07:52:43 -0000
- Subject: [Bug c/32166] Condition check for const char string fails
- References: <bug-32166-14589@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from kmanjunat at gmail dot com 2007-06-01 07:52 -------
The test case is being called from a shared library with the
eabi support using dlopen.
The following is the test case
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main()
{
char *a=NULL;
char *b="abcd";
char *ret=NULL;
ret=fun(a);
printf("%s \n", ret);
ret=fun(b);
printf("%s \n", ret);
return 0;
}
Definition of fun() is in the shared library
as follows :
char *fun(str)
const char *str;
{
int len;
char *copy;
if (str == NULL)
{
printf("Error, Null string passed \n");
return(NULL);
}
len = strlen(str) + 1;
if(!(copy = malloc(len)))
return(NULL);
memcpy(copy, str, len);
return(copy);
}
The control is not getting into the condition check
"if(str == NULL)". Ive verified this with the objdump of the
testcase, which does not show the "cmp instruction"
for the if (str == NULL) condition checking.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32166