Skip to content
  • Jeff King's avatar
    bulk-checkin: zero-initialize hashfile_checkpoint · 7140414d
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    We declare a "struct hashfile_checkpoint" but only sometimes actually
    call hashfile_checkpoint() on it. That makes it not immediately obvious
    that it's valid when we later access its members.
    
    In fact, the code is fine: we fill it in unconditionally in the while(1)
    loop as long as "idx" is non-NULL. And then if "idx" is NULL, we exit
    early from the function (because we're just computing the hash, not
    actually writing), before we look at the struct.
    
    However, this does seem to confuse gcc 9.2.1's -Wmaybe-uninitialized
    when compiled with "-flto -O2" (probably because with LTO it can now
    realize that our call to hashfile_truncate() does not set the members
    either). Let's zero-initialize the struct to tell the compiler, as well
    as any readers of the code, that all is well.
    
    Reported-by: default avatarStephan Beyer <s-beyer@gmx.net>
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    7140414d