{"thread":{"id":"58997","subject":"[PATCH] range-diff: heck for NULL over comparisons","startedAt":"2022-12-22T22:01:14Z","lastAt":"2022-12-23T19:25:52Z","messageCount":2,"participants":["Rose via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"469481","messageId":"pull.1415.git.git.1671746464482.gitgitgadget@gmail.com","threadId":"58997","inReplyTo":null,"subject":"[PATCH] range-diff: heck for NULL over comparisons","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-22T22:01:04Z","receivedAt":"2022-12-22T22:01:14Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nAlthough at first it may seem easier to\ncheck for the same comparison that\ndetermined whether a_util or b_util is NULL\nor not, checking for null directly\nwould make more sense for developers\nand static analysis tools, which false-flag\nthis area specifically as having potential NULL\npointers.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    range-diff: heck for NULL over comparisons\n    \n    Although at first it may seem easier to check for the same comparison\n    that determined whether a_util or b_util is NULL or not, checking for\n    null directly would make more sense for developers and static analysis\n    tools, which false-flag this area specifically as having potential NULL\n    pointers.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1415%2FAtariDreams%2Fmore-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1415/AtariDreams/more-v1\nPull-Request: https://github.com/git/git/pull/1415\n\n range-diff.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/range-diff.c b/range-diff.c\nindex 8b7d81adc1b..a5f5996c0ec 100644\n--- a/range-diff.c\n+++ b/range-diff.c\n@@ -506,11 +506,11 @@ static void output(struct string_list *a, struct string_list *b,\n \t\tb_util = j < b->nr ? b->items[j].util : NULL;\n \n \t\t/* Skip all the already-shown commits from the LHS. */\n-\t\twhile (i < a->nr && a_util->shown)\n+\t\twhile (a_util && a_util->shown)\n \t\t\ta_util = ++i < a->nr ? a->items[i].util : NULL;\n \n \t\t/* Show unmatched LHS commit whose predecessors were shown. */\n-\t\tif (i < a->nr && a_util->matching < 0) {\n+\t\tif (a_util && a_util->matching < 0) {\n \t\t\tif (!range_diff_opts->right_only)\n \t\t\t\toutput_pair_header(&opts, patch_no_width,\n \t\t\t\t\t   &buf, &dashes, a_util, NULL);\n@@ -519,7 +519,7 @@ static void output(struct string_list *a, struct string_list *b,\n \t\t}\n \n \t\t/* Show unmatched RHS commits. */\n-\t\twhile (j < b->nr && b_util->matching < 0) {\n+\t\twhile (b_util && b_util->matching < 0) {\n \t\t\tif (!range_diff_opts->left_only)\n \t\t\t\toutput_pair_header(&opts, patch_no_width,\n \t\t\t\t\t   &buf, &dashes, NULL, b_util);\n@@ -527,7 +527,7 @@ static void output(struct string_list *a, struct string_list *b,\n \t\t}\n \n \t\t/* Show matching LHS/RHS pair. */\n-\t\tif (j < b->nr) {\n+\t\tif (b_util) {\n \t\t\ta_util = a->items[b_util->matching].util;\n \t\t\toutput_pair_header(&opts, patch_no_width,\n \t\t\t\t\t   &buf, &dashes, a_util, b_util);\n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"},{"id":"469498","messageId":"pull.1415.v2.git.git.1671823544512.gitgitgadget@gmail.com","threadId":"58997","inReplyTo":"pull.1415.git.git.1671746464482.gitgitgadget@gmail.com","subject":"[PATCH v2] range-diff: check for NULL over comparisons","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-23T19:25:44Z","receivedAt":"2022-12-23T19:25:52Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nAlthough at first it may seem easier to\ncheck for the same comparison that\ndetermined whether a_util or b_util is NULL\nor not, checking for null directly\nwould make more sense for developers\nand static analysis tools, which false-flag\nthis area specifically as having potential NULL\npointers.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    range-diff: check for NULL over comparisons\n    \n    Although at first it may seem easier to check for the same comparison\n    that determined whether a_util or b_util is NULL or not, checking for\n    null directly would make more sense for developers and static analysis\n    tools, which false-flag this area specifically as having potential NULL\n    pointers.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1415%2FAtariDreams%2Fmore-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1415/AtariDreams/more-v2\nPull-Request: https://github.com/git/git/pull/1415\n\nRange-diff vs v1:\n\n 1:  b0e92aaf227 ! 1:  e3d850ff3ea range-diff: heck for NULL over comparisons\n     @@ Metadata\n      Author: Seija Kijin <doremylover123@gmail.com>\n      \n       ## Commit message ##\n     -    range-diff: heck for NULL over comparisons\n     +    range-diff: check for NULL over comparisons\n      \n          Although at first it may seem easier to\n          check for the same comparison that\n\n\n range-diff.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/range-diff.c b/range-diff.c\nindex 8b7d81adc1b..a5f5996c0ec 100644\n--- a/range-diff.c\n+++ b/range-diff.c\n@@ -506,11 +506,11 @@ static void output(struct string_list *a, struct string_list *b,\n \t\tb_util = j < b->nr ? b->items[j].util : NULL;\n \n \t\t/* Skip all the already-shown commits from the LHS. */\n-\t\twhile (i < a->nr && a_util->shown)\n+\t\twhile (a_util && a_util->shown)\n \t\t\ta_util = ++i < a->nr ? a->items[i].util : NULL;\n \n \t\t/* Show unmatched LHS commit whose predecessors were shown. */\n-\t\tif (i < a->nr && a_util->matching < 0) {\n+\t\tif (a_util && a_util->matching < 0) {\n \t\t\tif (!range_diff_opts->right_only)\n \t\t\t\toutput_pair_header(&opts, patch_no_width,\n \t\t\t\t\t   &buf, &dashes, a_util, NULL);\n@@ -519,7 +519,7 @@ static void output(struct string_list *a, struct string_list *b,\n \t\t}\n \n \t\t/* Show unmatched RHS commits. */\n-\t\twhile (j < b->nr && b_util->matching < 0) {\n+\t\twhile (b_util && b_util->matching < 0) {\n \t\t\tif (!range_diff_opts->left_only)\n \t\t\t\toutput_pair_header(&opts, patch_no_width,\n \t\t\t\t\t   &buf, &dashes, NULL, b_util);\n@@ -527,7 +527,7 @@ static void output(struct string_list *a, struct string_list *b,\n \t\t}\n \n \t\t/* Show matching LHS/RHS pair. */\n-\t\tif (j < b->nr) {\n+\t\tif (b_util) {\n \t\t\ta_util = a->items[b_util->matching].util;\n \t\t\toutput_pair_header(&opts, patch_no_width,\n \t\t\t\t\t   &buf, &dashes, a_util, b_util);\n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"}]}