{"thread":{"id":"20214","subject":"[PATCH] Fix export_marks() error handling.","startedAt":"2009-07-24T08:17:13Z","lastAt":"2009-07-24T16:35:44Z","messageCount":2,"participants":["Matthias Andree","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"118618","messageId":"1248423433-25407-1-git-send-email-matthias.andree@gmx.de","threadId":"20214","inReplyTo":"7v7hxyyfcg.fsf@alter.siamese.dyndns.org","subject":"[PATCH] Fix export_marks() error handling.","fromName":"Matthias Andree","fromEmail":"matthias.andree@gmx.de","sentAt":"2009-07-24T08:17:13Z","receivedAt":"2009-07-24T08:17:13Z","isPatch":true,"sender":{"key":"matthias.andree@gmx.de","avatar":null},"body":"- Don't leak one FILE * on error per export_marks() call. Found with\n  cppcheck and reported by Martin Ettl.\n\n- Abort the potentially long for(;idnums.size;) loop on write errors.\n\n- Record error if fprintf() fails for reasons not required to set the\n  stream error indicator, such as ENOMEM.\n\n- Add a trailing full-stop to error message when fopen() fails.\n\nSigned-off-by: Matthias Andree <matthias.andree@gmx.de>\n---\n builtin-fast-export.c |   14 ++++++++++----\n 1 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 9a8a6fc..ca19825 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -428,21 +428,27 @@ static void export_marks(char *file)\n \tuint32_t mark;\n \tstruct object_decoration *deco = idnums.hash;\n \tFILE *f;\n+\tint e = 0;\n \n \tf = fopen(file, \"w\");\n \tif (!f)\n-\t\terror(\"Unable to open marks file %s for writing\", file);\n+\t\terror(\"Unable to open marks file %s for writing.\", file);\n \n \tfor (i = 0; i < idnums.size; i++) {\n \t\tif (deco->base && deco->base->type == 1) {\n \t\t\tmark = ptr_to_mark(deco->decoration);\n-\t\t\tfprintf(f, \":%\"PRIu32\" %s\\n\", mark,\n-\t\t\t\tsha1_to_hex(deco->base->sha1));\n+\t\t\tif (fprintf(f, \":%\"PRIu32\" %s\\n\", mark,\n+\t\t\t\tsha1_to_hex(deco->base->sha1)) < 0) {\n+\t\t\t    e = 1;\n+\t\t\t    break;\n+\t\t\t}\n \t\t}\n \t\tdeco++;\n \t}\n \n-\tif (ferror(f) || fclose(f))\n+\te |= ferror(f);\n+\te |= fclose(f);\n+\tif (e)\n \t\terror(\"Unable to write marks file %s.\", file);\n }\n \n-- \n1.6.3.3.413.g91e7\n"},{"id":"118638","messageId":"7vskgmkpi7.fsf@alter.siamese.dyndns.org","threadId":"20214","inReplyTo":"1248423433-25407-1-git-send-email-matthias.andree@gmx.de","subject":"Re: [PATCH] Fix export_marks() error handling.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-24T16:35:44Z","receivedAt":"2009-07-24T16:35:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, will apply.\n"}]}