nelhage / reptyr

Reparent a running program to a new terminal
MIT License
5.77k stars 216 forks source link

gcc believes that "scratch" might be uninitialized after grab_pid #63

Closed ony closed 8 years ago

ony commented 8 years ago

gcc-4.9.2 and gcc-5.2.0 issue an error during build:

<builtin>: recipe for target 'attach.o' failed
ionice -c 3 nice -n 19 make -j12 --load-average=8
In file included from attach.c:46:0:
attach.c: In function 'steal_block_hup':
platform/platform.h:38:5: error: 'scratch' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     ptrace_remote_syscall((child), ptrace_syscall_numbers((child))->nr_##name, \
     ^
attach.c:487:18: note: 'scratch' was declared here
     child_addr_t scratch;
                  ^
cc1: all warnings being treated as errors
make: *** [attach.o] Error 1

Though according to code of steal_block_hup:

    if ((err = grab_pid(steal->target_stat.sid, &leader, &scratch)))
        return err;

And in grab_pid:

    if ((err = mmap_scratch(child, scratch)))
        goto out_restore_regs; 

Which means that error propagated correctly.

Maybe code of mmap_scratch confuses compiler:

    if (scratch_page > (unsigned long) - 1000) {
        return -(signed long)scratch_page;
    }

    *addr = scratch_page;

Though it is clear that there no way to get 0 before assigning scratch_page to *addr.

Note that clang 3.7.0 able to build this code.

nelhage commented 8 years ago

Does the above commit fix it? Seems like the easiest fix.

We had some vaguely similar issues with the clang analyzer that were fixed in f6f156365b15542714da601d2e26eecc49bbdeb0, but this one isn't obviously errno-related.

ony commented 8 years ago

Yes this helps. Thank you.