This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/1973] getenv returns pointer to unallocated space.


------- Additional Comments From lepinat at free dot fr  2006-04-03 18:51 -------
I found where the problem come from, but I can't understand why it's append,
 and I would like to know.
On the samples sended  by marvin.nospam@gmail.com

if it compiled on the 32bits mode (-m32) no problem
if it compiled on the 64bits mode (-m64) SegFault

on the samples if we add the line #include <stdlib.h> on the 64bits mode, 
the problem disappear!

---->8---->8---->8-----
# Makefile
CC:=gcc
#CFLAGS:=-enable-checking -g -O0 -v -Q -da
CFLAGS:= -g

BINARY:= test_getenv64 test_getenv64_segfault test_getenv32

all: $(BINARY)

test_getenv64_segfault: test_getenv.c
	$(CC) $(CFLAGS)  $^ -o $@

test_getenv64: test_getenv.c
	$(CC) $(CFLAGS) -DNO_FAULT $^ -o $@

test_getenv32: test_getenv.c
	$(CC) $(CFLAGS) $^ -o $@

clean:
	rm -f *.o $(BINARY) 

---->8---->8---->8-----
/* test_getenv.c */
#include <stdio.h>

#ifdef NO_FAULT
#include <stdlib.h>
#endif

main()
{
    char *home =  getenv("HOME");
    if (!home)	{
        printf("ptr=NULL\n");
    }
    else {
        printf ("path=%s\n", home);
    }
}




-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
              Alias|                            |getenv_problem
             Status|RESOLVED                    |REOPENED
 GCC target triplet|                            |x86_64
         Resolution|WORKSFORME                  |


http://sourceware.org/bugzilla/show_bug.cgi?id=1973

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]