orangeduck / tgc

A Tiny Garbage Collector for C
Other
968 stars 64 forks source link

Conditional jump or move depends on uninitialised value(s) #20

Closed ClaudioDaffra closed 2 years ago

ClaudioDaffra commented 3 years ago

// example conditional jump error

#include "../lib/tgc.h"

static tgc_t gc;

static void example_function() {
  void *memory = tgc_alloc(&gc, 1024);
}

int main(int argc, char **argv) {

  tgc_start(&gc, &argc);

  example_function();

  tgc_stop(&gc);

  return 0;
}

valgrind error :

claudio@xubuntu20vm:~/cxx$ valgrind ./x
==2891== Memcheck, a memory error detector
==2891== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2891== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==2891== Command: ./x
==2891== 
==2891== Conditional jump or move depends on uninitialised value(s)
==2891==    at 0x109BF5: tgc_mark_ptr (in /home/claudio/cxx/x)
==2891==    by 0x109E9A: tgc_mark_stack (in /home/claudio/cxx/x)
==2891==    by 0x10A12B: tgc_mark (in /home/claudio/cxx/x)
==2891==    by 0x10A863: tgc_run (in /home/claudio/cxx/x)
==2891==    by 0x10A948: tgc_add (in /home/claudio/cxx/x)
==2891==    by 0x10AC18: tgc_alloc_opt (in /home/claudio/cxx/x)
==2891==    by 0x10A9FB: tgc_alloc (in /home/claudio/cxx/x)
==2891==    by 0x10ADFB: example_function (in /home/claudio/cxx/x)
==2891==    by 0x10AE32: main (in /home/claudio/cxx/x)
==2891== 
==2891== Conditional jump or move depends on uninitialised value(s)
==2891==    at 0x109BF5: tgc_mark_ptr (in /home/claudio/cxx/x)
==2891==    by 0x109D94: tgc_mark_ptr (in /home/claudio/cxx/x)
==2891==    by 0x109E9A: tgc_mark_stack (in /home/claudio/cxx/x)
==2891==    by 0x10A12B: tgc_mark (in /home/claudio/cxx/x)
==2891==    by 0x10A863: tgc_run (in /home/claudio/cxx/x)
==2891==    by 0x10A948: tgc_add (in /home/claudio/cxx/x)
==2891==    by 0x10AC18: tgc_alloc_opt (in /home/claudio/cxx/x)
==2891==    by 0x10A9FB: tgc_alloc (in /home/claudio/cxx/x)
==2891==    by 0x10ADFB: example_function (in /home/claudio/cxx/x)
==2891==    by 0x10AE32: main (in /home/claudio/cxx/x)
==2891== 
==2891== Conditional jump or move depends on uninitialised value(s)
==2891==    at 0x109C0A: tgc_mark_ptr (in /home/claudio/cxx/x)
==2891==    by 0x109E9A: tgc_mark_stack (in /home/claudio/cxx/x)
==2891==    by 0x10A12B: tgc_mark (in /home/claudio/cxx/x)
==2891==    by 0x10A863: tgc_run (in /home/claudio/cxx/x)
==2891==    by 0x10A948: tgc_add (in /home/claudio/cxx/x)
==2891==    by 0x10AC18: tgc_alloc_opt (in /home/claudio/cxx/x)
==2891==    by 0x10A9FB: tgc_alloc (in /home/claudio/cxx/x)
==2891==    by 0x10ADFB: example_function (in /home/claudio/cxx/x)
==2891==    by 0x10AE32: main (in /home/claudio/cxx/x)
==2891== 
==2891== 
==2891== HEAP SUMMARY:
==2891==     in use at exit: 0 bytes in 0 blocks
==2891==   total heap usage: 5 allocs, 5 frees, 1,304 bytes allocated
==2891== 
==2891== All heap blocks were freed -- no leaks are possible
==2891== 
==2891== Use --track-origins=yes to see where uninitialised values come from
==2891== For lists of detected and suppressed errors, rerun with: -s
==2891== ERROR SUMMARY: 142 errors from 3 contexts (suppressed: 0 from 0)
claudio@xubuntu20vm:~/cxx$
nrootconauto commented 2 years ago

The garbage collector scans all "visible" memory that may or not me initialized ,this isnt really an issue if this garbage collector,but of all garbage collectors.

orangeduck commented 2 years ago

Yes this issue is known:

https://github.com/orangeduck/tgc#why-do-i-get-uninitialised-values-warnings-with-valgrind