{"thread":{"id":"4245","subject":"[PATCH 2/2] added more informative error messages to git-mktag","startedAt":"2006-05-22T14:49:53Z","lastAt":"2006-05-22T19:22:50Z","messageCount":2,"participants":["Björn Engelmann","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"20453","messageId":"4471CF91.9010202@gmx.de","threadId":"4245","inReplyTo":null,"subject":"[PATCH 2/2] added more informative error messages to git-mktag","fromName":"Björn Engelmann","fromEmail":"bjengelmann@gmx.de","sentAt":"2006-05-22T14:49:53Z","receivedAt":"2006-05-22T14:49:53Z","isPatch":true,"sender":{"key":"bjengelmann@gmx.de","avatar":null},"body":"\nSigned-off-by: Björn Engelmann <BjEngelmann@gmx.de>\n\n\n---\n\n5045fd2336abbe57f191e8839759369ee1c7cc6e\n mktag.c |   41 +++++++++++++++++++++++++++++++----------\n 1 files changed, 31 insertions(+), 10 deletions(-)\n\n5045fd2336abbe57f191e8839759369ee1c7cc6e\ndiff --git a/mktag.c b/mktag.c\nindex 79c466c..9f4878c 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -45,42 +45,60 @@ static int verify_tag(char *buffer, unsi\n     unsigned char sha1[20];\n     const char *object, *type_line, *tag_line, *tagger_line;\n \n-    if (size < 64)\n+    if (size < 64) {\n+        printf(\"wanna fool me ? you obviously got the size wrong !\\n\");\n         return -1;\n+    }\n     buffer[size] = 0;\n \n     /* Verify object line */\n     object = buffer;\n-    if (memcmp(object, \"object \", 7))\n+    if (memcmp(object, \"object \", 7)) {\n+        printf(\"char%i: does not start with \\\"object \\\"\\n\", 0);\n         return -1;\n-    if (get_sha1_hex(object + 7, sha1))\n+    }\n+    if (get_sha1_hex(object + 7, sha1)) {\n+        printf(\"char%i: could not get SHA1 hash\\n\", 7);\n         return -1;\n+    }\n \n     /* Verify type line */\n     type_line = object + 48;\n-    if (memcmp(type_line - 1, \"\\ntype \", 6))\n+    if (memcmp(type_line - 1, \"\\ntype \", 6)) {\n+        printf(\"char%i: could not find \\\"\\\\ntype \\\"\\n\", 47);\n         return -1;\n+    }\n \n     /* Verify tag-line */\n     tag_line = strchr(type_line, '\\n');\n-    if (!tag_line)\n+    if (!tag_line) {\n+        printf(\"char%i: could not find next \\\"\\\\n\\\"\\n\", (int)type_line\n- (int)buffer);\n         return -1;\n+    }\n     tag_line++;\n-    if (memcmp(tag_line, \"tag \", 4) || tag_line[4] == '\\n')\n+    if (memcmp(tag_line, \"tag \", 4) || tag_line[4] == '\\n') {\n+        printf(\"char%i: no \\\"tag \\\" found\\n\", (int)tag_line - (int)buffer);\n         return -1;\n+    }\n \n     /* Get the actual type */\n     typelen = tag_line - type_line - strlen(\"type \\n\");\n-    if (typelen >= sizeof(type))\n+    if (typelen >= sizeof(type)) {\n+        printf(\"char%i: type too long\\n\", (int)type_line + strlen(\"type\n\\n\") - (int)buffer);\n         return -1;\n+    }\n     memcpy(type, type_line+5, typelen);\n     type[typelen] = 0;\n \n     /* Verify that the object matches */\n-    if (get_sha1_hex(object + 7, sha1))\n+    if (get_sha1_hex(object + 7, sha1)) {\n+        printf(\"char%i: could not get SHA1 hash but this is really odd\nsince i got it before !\\n\", 7);\n         return -1;\n-    if (verify_object(sha1, type))\n+    }\n+    if (verify_object(sha1, type)) {\n+        printf(\"char%i: could not verify object %s\\n\", 7, sha1);\n         return -1;\n+    }\n \n     /* Verify the tag-name: we don't allow control characters or spaces\nin it */\n     tag_line += 4;\n@@ -90,14 +108,17 @@ static int verify_tag(char *buffer, unsi\n             break;\n         if (c > ' ')\n             continue;\n+        printf(\"char%i: could not verify tag name\\n\", (int)tag_line -\n(int)buffer);\n         return -1;\n     }\n \n     /* Verify the tagger line */\n     tagger_line = tag_line;\n \n-    if (memcmp(tagger_line, \"tagger\", 6) || (tagger_line[6] == '\\n'))\n+    if (memcmp(tagger_line, \"tagger\", 6) || (tagger_line[6] == '\\n')) {\n+        printf(\"char%i: could not find \\\"tagger\\\"\\n\", (int)tagger_line\n- (int)buffer);\n         return -1;\n+    }\n \n     /* The actual stuff afterwards we don't care about.. */\n     return 0;\n-- \n1.3.3.g5045-dirty\n"},{"id":"20466","messageId":"7vu07hamph.fsf@assigned-by-dhcp.cox.net","threadId":"4245","inReplyTo":"4471CF91.9010202@gmx.de","subject":"Re: [PATCH 2/2] added more informative error messages to git-mktag","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-22T19:22:50Z","receivedAt":"2006-05-22T19:22:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Björn Engelmann <BjEngelmann@gmx.de> writes:\n\n> -    if (size < 64)\n> +    if (size < 64) {\n> +        printf(\"wanna fool me ? you obviously got the size wrong !\\n\");\n>          return -1;\n> +    }\n\nPlease do this instead:\n\n\treturn error(\"wanna ...\");\n\nyou can lose the braces and the message goes to the stderr.\n\n> -    if (memcmp(object, \"object \", 7))\n> +    if (memcmp(object, \"object \", 7)) {\n> +        printf(\"char%i: does not start with \\\"object \\\"\\n\", 0);\n>          return -1;\n\nAlthough they may be synonyms, we tend to use %d for ints and it\nis more conventional.\n\n>      tag_line++;\n> -    if (memcmp(tag_line, \"tag \", 4) || tag_line[4] == '\\n')\n> +    if (memcmp(tag_line, \"tag \", 4) || tag_line[4] == '\\n') {\n> +        printf(\"char%i: no \\\"tag \\\" found\\n\", (int)tag_line - (int)buffer);\n>          return -1;\n> +    }\n\nIf you have to cast, please do not cast pointers to ints and\ntake their difference, but take the difference and cast the\nresulting ptrdiff_t to int, like this:\n\n\t(int)(tag_line - buffer)\n\nOr use \"%td\" instead of \"%i\" and lose the cast.\n"}]}