Sebastian Götte <jaseg@xxxxxxxxxxxxxxxxxxx> writes: > Signed-off-by: Sebastian Götte <jaseg@xxxxxxxxxxxxxxxxxxxxxxxx> > --- > commit.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/commit.c b/commit.c > index 1aeb17a..533727c 100644 > --- a/commit.c > +++ b/commit.c > @@ -1027,8 +1027,8 @@ static struct { > char result; > const char *check; > } signature_check[] = { > - { 'G', "\n[GNUPG:] GOODSIG " }, > - { 'B', "\n[GNUPG:] BADSIG " }, > + { 'G', "[GNUPG:] GOODSIG " }, > + { 'B', "[GNUPG:] BADSIG " }, > }; > > static void parse_signature_lines(struct signature *sig) > @@ -1041,6 +1041,9 @@ static void parse_signature_lines(struct signature *sig) > const char *next; > if (!found) > continue; > + if (found != buf) > + if (found[-1] != '\n') > + continue; It would be much easier to read if it were "unless we are not looking at the very first byte, the previous byte must be LF", i.e. if (found != buf && found[-1] != '\n') Is that continue correct? Don't you want to retry from the end of the line that contains the mistaken hit? The "\n" at the beginning anchors the expected string for quicker multi-line scan done with strstr(). If you really want to lose that LF and still write this function correctly and clearly, I think you would need to iterate over the buffer line by line. What you want to do may be more like this, I think. commit.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/commit.c b/commit.c index d093c9c..d6e0b00 100644 --- a/commit.c +++ b/commit.c @@ -1045,8 +1045,8 @@ static struct { char result; const char *check; } signature_check[] = { - { 'G', "[GNUPG:] GOODSIG " }, - { 'B', "[GNUPG:] BADSIG " }, + { 'G', "\n[GNUPG:] GOODSIG " }, + { 'B', "\n[GNUPG:] BADSIG " }, }; static void parse_signature_lines(struct signature *sig) @@ -1055,15 +1055,18 @@ static void parse_signature_lines(struct signature *sig) int i; for (i = 0; i < ARRAY_SIZE(signature_check); i++) { - const char *found = strstr(buf, signature_check[i].check); - const char *next; - if (!found) - continue; - if (found != buf) - if (found[-1] != '\n') + const char *found, *next; + + if (!prefixcmp(buf, signature_check[i].check + 1)) { + /* At the very beginning of the buffer */ + found = buf + strlen(signature_check[i].check + 1); + } else { + found = strstr(buf, signature_check[i].check); + if (!found) continue; + found += strlen(signature_check[i].check); + } sig->check_result = signature_check[i].result; - found += strlen(signature_check[i].check); sig->key = xmemdupz(found, 16); found += 17; next = strchrnul(found, '\n'); -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html