=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/file/magic-test.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- src/usr.bin/file/magic-test.c 2015/08/12 07:43:27 1.11 +++ src/usr.bin/file/magic-test.c 2015/08/12 09:29:49 1.12 @@ -1,4 +1,4 @@ -/* $OpenBSD: magic-test.c,v 1.11 2015/08/12 07:43:27 nicm Exp $ */ +/* $OpenBSD: magic-test.c,v 1.12 2015/08/12 09:29:49 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -677,7 +677,7 @@ if (result == !ml->test_not) { if (ml->result != NULL) magic_add_string(ms, ml, s, slen); - if (result) + if (result && ml->test_operator == '=') ms->offset += slen + 1; } return (result); @@ -919,8 +919,9 @@ m.rm_eo = ms->size; result = (regexec(&re, ms->base, 1, &m, REG_STARTEND) == 0); - if (result == !ml->test_not && ml->result != NULL) { - magic_add_result(ms, ml, "%s", ""); + if (result == !ml->test_not) { + if (ml->result != NULL) + magic_add_result(ms, ml, "%s", ""); if (result) { if (sflag) ms->offset = m.rm_so; @@ -1022,9 +1023,11 @@ } result = (found != NULL); - if (result == !ml->test_not && ml->result != NULL && found != NULL) { - magic_add_string(ms, ml, found, ms->size - ms->offset); - ms->offset = found - start + size; + if (result == !ml->test_not) { + if (ml->result != NULL) + magic_add_string(ms, ml, found, ms->size - ms->offset); + if (result && found != NULL && ml->test_operator == '=') + ms->offset = (found + size) - ms->base; } return (result); }