summaryrefslogtreecommitdiff
path: root/run-command.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-08-11 05:24:35 -0400
committerJunio C Hamano <gitster@pobox.com>2016-08-11 10:42:23 -0700
commit27b5c1a0653026645bd6908ee5abfdceb1c95082 (patch)
tree57d9b7f106d335340624d4fec151c018f467af35 /run-command.h
parent56dfeb62638760fa78a442a97f19abf1af374d29 (diff)
downloadgit-27b5c1a0653026645bd6908ee5abfdceb1c95082.tar.gz
provide an initializer for "struct object_info"
An all-zero initializer is fine for this struct, but because the first element is a pointer, call sites need to know to use "NULL" instead of "0". Otherwise some static checkers like "sparse" will complain; see d099b71 (Fix some sparse warnings, 2013-07-18) for example. So let's provide an initializer to make this easier to get right. But let's also comment that memset() to zero is explicitly OK[1]. One of the callers embeds object_info in another struct which is initialized via memset (expand_data in builtin/cat-file.c). Since our subset of C doesn't allow assignment from a compound literal, handling this in any other way is awkward, so we'd like to keep the ability to initialize by memset(). By documenting this property, it should make anybody who wants to change the initializer think twice before doing so. There's one other caller of interest. In parse_sha1_header(), we did not initialize the struct fully in the first place. This turned out not to be a bug because the sub-function it calls does not look at any other fields except the ones we did initialize. But that assumption might not hold in the future, so it's a dangerous construct. This patch switches it to initializing the whole struct, which protects us against unexpected reads of the other fields. [1] Obviously using memset() to initialize a pointer violates the C standard, but we long ago decided that it was an acceptable tradeoff in the real world. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'run-command.h')
0 files changed, 0 insertions, 0 deletions