path: root/builtin/am.c
diff options
authorJeff King <>2016-07-08 09:06:50 (GMT)
committerJunio C Hamano <>2016-07-08 16:47:28 (GMT)
commitaabbd3f3c9dd17c414100d0e029f8a3d13673ab1 (patch)
tree2e803c866f90395deac63bf644d47ecb80c0adb0 /builtin/am.c
parent05219a1276341e72d8082d76b7f5ed394b7437a4 (diff)
config: fix bogus fd check when setting up default config
Since 9830534 (config --global --edit: create a template file if needed, 2014-07-25), an edit of the global config file will try to open() it with O_EXCL, and wants to handle three cases: 1. We succeeded; the user has no config file, and we should fill in the default template. 2. We got EEXIST; they have a file already, proceed as usual. 3. We got another error; we should complain. However, the check for case 1 does "if (fd)", which will generally _always_ be true (except for the oddball case that somehow our stdin got closed and opening really did give us a new descriptor 0). So in the EEXIST case, we tried to write the default config anyway! Fortunately, this turns out to be a noop, since we just end up writing to and closing "-1", which does nothing. But in case 3, we would fail to notice any other errors, and just silently continue (given that we don't actually notice write errors for the template either, it's probably not that big a deal; we're about to spawn the editor, so it would notice any problems. But the code is clearly _trying_ to hit cover this case and failing). We can fix it easily by using "fd >= 0" for case 1. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/am.c')
0 files changed, 0 insertions, 0 deletions