----------------------------------------
> Date: Fri, 16 Dec 2011 08:53:19 +0000
> From: t...@compton.nu
> To: vuo...@msn.com
> CC: valgrind-users@lists.sourceforge.net
> Subject: Re: Conditional jump or move depends on uninitialised value and its 
> reason
>
> On 16/12/11 08:41, Hannu Vuolasaho wrote:
>
> > I wrote small test case which gave same Conditional jump or move depends on 
> > uninitialised value errors.
> >
> > #include
> > #include
> >
> > int main(){
> > char * buffer;
> > size_t size;
> >
> > if(getline(&buffer,&size, stdin)>0){
> > fputs(buffer, stdout);
> > free(buffer);
> > }
> > }
> >
> > What I'm doing wrong? Should I use fread and fwrite?
>
> You didn't initialise buffer to NULL before calling getline so it's
> behaviour is not deterministic. In particular when it checks whether the
> argument is NULL so as to decide whether to allocate a buffer it will be
> checking an uninitialised value.

Yes I did. The evil copy eater before paste just ate it :)  I saw that bug and 
forgot to paste fixed version.
I still get errors from puts().

I'm using Arch Linux and found old bug about strlen and SSE instructions among 
other thing. Also there was some posts about stripped libc and I have:
$ file /lib/libc-2.14.1.so
/lib/libc-2.14.1.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), 
dynamically linked (uses shared libs), 
BuildID[sha1]=0x84c4a5b908da76082cff58f393bee5d9c15d9684, for GNU/Linux 2.6.27, 
stripped

Does that have something to do with puts() error?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  char * buffer = NULL;
  size_t size = 0;
  int len = 0;
  if(getline(&buffer, &size, stdin) >0 && buffer != NULL ){
    if(strlen(buffer) > 0){
      fputs(buffer, stdout);
    }
  }
  if(buffer != NULL){
    free(buffer);
  }
}

valgrind --tool=memcheck --leak-check=yes --show-reachable=yes 
--num-callers=20  ./read_test
==2001== Memcheck, a memory error detector
==2001== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==2001== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==2001== Command: ./read_test
==2001== 
foo
==2001== Conditional jump or move depends on uninitialised value(s)
==2001==    at 0x4EAB5FF: ??? (in /lib/libc-2.14.1.so)
==2001==    by 0x4E9354D: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
==2001== Conditional jump or move depends on uninitialised value(s)
==2001==    at 0x4E9DBBB: _IO_file_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E935CC: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
==2001== Conditional jump or move depends on uninitialised value(s)
==2001==    at 0x4E9DC1F: _IO_file_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E935CC: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
==2001== Conditional jump or move depends on uninitialised value(s)
==2001==    at 0x4E9DC28: _IO_file_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E935CC: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
==2001== Conditional jump or move depends on uninitialised value(s)
==2001==    at 0x4E9F823: _IO_default_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E9DC39: _IO_file_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E935CC: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
==2001== Conditional jump or move depends on uninitialised value(s)
==2001==    at 0x4E9F881: _IO_default_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E9DC39: _IO_file_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E935CC: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
==2001== Use of uninitialised value of size 8
==2001==    at 0x4E9F88B: _IO_default_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E9DC39: _IO_file_xsputn (in /lib/libc-2.14.1.so)
==2001==    by 0x4E935CC: fputs (in /lib/libc-2.14.1.so)
==2001==    by 0x400671: main (read_test.c:11)
==2001== 
foo
==2001== 
==2001== HEAP SUMMARY:
==2001==     in use at exit: 0 bytes in 0 blocks
==2001==   total heap usage: 1 allocs, 1 frees, 120 bytes allocated
==2001== 
==2001== All heap blocks were freed -- no leaks are possible
==2001== 
==2001== For counts of detected and suppressed errors, rerun with: -v
==2001== Use --track-origins=yes to see where uninitialised values come from
==2001== ERROR SUMMARY: 14 errors from 7 contexts (suppressed: 6 from 6)
                                          
------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to