зеркало из https://github.com/microsoft/git.git
xutils: Fix hashing an incomplete line with whitespaces at the end
Upon seeing a whitespace, xdl_hash_record_with_whitespace() first skipped the run of whitespaces (excluding LF) that begins there, ensuring that the pointer points at the last whitespace character in the run, and assumed that the next character must be LF at the end of the line. This does not work when hashing an incomplete line, which lacks the LF at the end. Introduce "at_eol" variable that is true when either we are at the end of line (looking at LF) or at the end of an incomplete line, and use that instead throughout the code. Noticed by Thell Fowler. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
0d5055665c
Коммит
78ed710fcf
|
@ -242,18 +242,20 @@ static unsigned long xdl_hash_record_with_whitespace(char const **data,
|
||||||
for (; ptr < top && *ptr != '\n'; ptr++) {
|
for (; ptr < top && *ptr != '\n'; ptr++) {
|
||||||
if (isspace(*ptr)) {
|
if (isspace(*ptr)) {
|
||||||
const char *ptr2 = ptr;
|
const char *ptr2 = ptr;
|
||||||
|
int at_eol;
|
||||||
while (ptr + 1 < top && isspace(ptr[1])
|
while (ptr + 1 < top && isspace(ptr[1])
|
||||||
&& ptr[1] != '\n')
|
&& ptr[1] != '\n')
|
||||||
ptr++;
|
ptr++;
|
||||||
|
at_eol = (top <= ptr + 1 || ptr[1] == '\n');
|
||||||
if (flags & XDF_IGNORE_WHITESPACE)
|
if (flags & XDF_IGNORE_WHITESPACE)
|
||||||
; /* already handled */
|
; /* already handled */
|
||||||
else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
|
else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
|
||||||
&& ptr[1] != '\n') {
|
&& !at_eol) {
|
||||||
ha += (ha << 5);
|
ha += (ha << 5);
|
||||||
ha ^= (unsigned long) ' ';
|
ha ^= (unsigned long) ' ';
|
||||||
}
|
}
|
||||||
else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
|
else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
|
||||||
&& ptr[1] != '\n') {
|
&& !at_eol) {
|
||||||
while (ptr2 != ptr + 1) {
|
while (ptr2 != ptr + 1) {
|
||||||
ha += (ha << 5);
|
ha += (ha << 5);
|
||||||
ha ^= (unsigned long) *ptr2;
|
ha ^= (unsigned long) *ptr2;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче