Skip to content

Commit cb0abea

Browse files
committed
add_excludes_from_file: clarify the bom skipping logic
Even though the previous step shifts where the "entry" begins, we still iterate over the original buf[], which may begin with the UTF-8 BOM we are supposed to be skipping. At the end of the first line, the code grabs the contents of it starting at "entry", so there is nothing wrong per-se, but the logic looks really confused. Instead, move the buf pointer and shrink its size, to truly pretend that UTF-8 BOM did not exist in the input. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 245e1c1 commit cb0abea

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

dir.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,11 @@ int add_excludes_from_file_to_list(const char *fname,
576576

577577
el->filebuf = buf;
578578

579-
if (size >= 3 && !memcmp(buf, utf8_bom, 3))
580-
entry = buf + 3;
581-
else
582-
entry = buf;
579+
if (size >= 3 && !memcmp(buf, utf8_bom, 3)) {
580+
buf += 3;
581+
size -= 3;
582+
}
583+
entry = buf;
583584

584585
for (i = 0; i < size; i++) {
585586
if (buf[i] == '\n') {

0 commit comments

Comments
 (0)