Skip to content

Commit ba4faf6

Browse files
committed
buf_text: remove offset parameter of BOM detection function
The function to detect a BOM takes an offset where it shall look for a BOM. No caller uses that, and searching for the BOM in the middle of a buffer seems to be very unlikely, as a BOM should only ever exist at file start. Remove the parameter, as it has already caused confusion due to its weirdness.
1 parent 2eea5f1 commit ba4faf6

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/buf_text.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool git_buf_text_is_binary(const git_buf *buf)
188188
git_bom_t bom;
189189
int printable = 0, nonprintable = 0;
190190

191-
scan += git_buf_text_detect_bom(&bom, buf, 0);
191+
scan += git_buf_text_detect_bom(&bom, buf);
192192

193193
if (bom > GIT_BOM_UTF8)
194194
return 1;
@@ -215,18 +215,18 @@ bool git_buf_text_contains_nul(const git_buf *buf)
215215
return (memchr(buf->ptr, '\0', buf->size) != NULL);
216216
}
217217

218-
int git_buf_text_detect_bom(git_bom_t *bom, const git_buf *buf, size_t offset)
218+
int git_buf_text_detect_bom(git_bom_t *bom, const git_buf *buf)
219219
{
220220
const char *ptr;
221221
size_t len;
222222

223223
*bom = GIT_BOM_NONE;
224-
/* need at least 2 bytes after offset to look for any BOM */
225-
if (buf->size < offset + 2)
224+
/* need at least 2 bytes to look for any BOM */
225+
if (buf->size < 2)
226226
return 0;
227227

228-
ptr = buf->ptr + offset;
229-
len = buf->size - offset;
228+
ptr = buf->ptr;
229+
len = buf->size;
230230

231231
switch (*ptr++) {
232232
case 0:
@@ -274,7 +274,7 @@ bool git_buf_text_gather_stats(
274274
memset(stats, 0, sizeof(*stats));
275275

276276
/* BOM detection */
277-
skip = git_buf_text_detect_bom(&stats->bom, buf, 0);
277+
skip = git_buf_text_detect_bom(&stats->bom, buf);
278278
if (skip_bom)
279279
scan += skip;
280280

src/buf_text.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ extern bool git_buf_text_contains_nul(const git_buf *buf);
9999
*
100100
* @param bom Set to the type of BOM detected or GIT_BOM_NONE
101101
* @param buf Buffer in which to check the first bytes for a BOM
102-
* @param offset Offset into buffer to look for BOM
103102
* @return Number of bytes of BOM data (or 0 if no BOM found)
104103
*/
105-
extern int git_buf_text_detect_bom(
106-
git_bom_t *bom, const git_buf *buf, size_t offset);
104+
extern int git_buf_text_detect_bom(git_bom_t *bom, const git_buf *buf);
107105

108106
/**
109107
* Gather stats for a piece of text

src/config_parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static int skip_bom(git_parse_ctx *parser)
217217
{
218218
git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len);
219219
git_bom_t bom;
220-
int bom_offset = git_buf_text_detect_bom(&bom, &buf, 0);
220+
int bom_offset = git_buf_text_detect_bom(&bom, &buf);
221221

222222
if (bom == GIT_BOM_UTF8)
223223
git_parse_advance_chars(parser, bom_offset);

0 commit comments

Comments
 (0)