@@ -942,28 +942,28 @@ static int gitdiff_newfile(const char *line, struct patch *patch)
942
942
static int gitdiff_copysrc (const char * line , struct patch * patch )
943
943
{
944
944
patch -> is_copy = 1 ;
945
- patch -> old_name = find_name (line , NULL , 0 , 0 );
945
+ patch -> old_name = find_name (line , NULL , p_value ? p_value - 1 : 0 , 0 );
946
946
return 0 ;
947
947
}
948
948
949
949
static int gitdiff_copydst (const char * line , struct patch * patch )
950
950
{
951
951
patch -> is_copy = 1 ;
952
- patch -> new_name = find_name (line , NULL , 0 , 0 );
952
+ patch -> new_name = find_name (line , NULL , p_value ? p_value - 1 : 0 , 0 );
953
953
return 0 ;
954
954
}
955
955
956
956
static int gitdiff_renamesrc (const char * line , struct patch * patch )
957
957
{
958
958
patch -> is_rename = 1 ;
959
- patch -> old_name = find_name (line , NULL , 0 , 0 );
959
+ patch -> old_name = find_name (line , NULL , p_value ? p_value - 1 : 0 , 0 );
960
960
return 0 ;
961
961
}
962
962
963
963
static int gitdiff_renamedst (const char * line , struct patch * patch )
964
964
{
965
965
patch -> is_rename = 1 ;
966
- patch -> new_name = find_name (line , NULL , 0 , 0 );
966
+ patch -> new_name = find_name (line , NULL , p_value ? p_value - 1 : 0 , 0 );
967
967
return 0 ;
968
968
}
969
969
@@ -1048,7 +1048,7 @@ static char *git_header_name(char *line, int llen)
1048
1048
{
1049
1049
const char * name ;
1050
1050
const char * second = NULL ;
1051
- size_t len ;
1051
+ size_t len , line_len ;
1052
1052
1053
1053
line += strlen ("diff --git " );
1054
1054
llen -= strlen ("diff --git " );
@@ -1148,22 +1148,22 @@ static char *git_header_name(char *line, int llen)
1148
1148
* Accept a name only if it shows up twice, exactly the same
1149
1149
* form.
1150
1150
*/
1151
+ second = strchr (name , '\n' );
1152
+ if (!second )
1153
+ return NULL ;
1154
+ line_len = second - name ;
1151
1155
for (len = 0 ; ; len ++ ) {
1152
1156
switch (name [len ]) {
1153
1157
default :
1154
1158
continue ;
1155
1159
case '\n' :
1156
1160
return NULL ;
1157
1161
case '\t' : case ' ' :
1158
- second = name + len ;
1159
- for (;;) {
1160
- char c = * second ++ ;
1161
- if (c == '\n' )
1162
- return NULL ;
1163
- if (c == '/' )
1164
- break ;
1165
- }
1166
- if (second [len ] == '\n' && !memcmp (name , second , len )) {
1162
+ second = stop_at_slash (name + len , line_len - len );
1163
+ if (!second )
1164
+ return NULL ;
1165
+ second ++ ;
1166
+ if (second [len ] == '\n' && !strncmp (name , second , len )) {
1167
1167
return xmemdupz (name , len );
1168
1168
}
1169
1169
}
0 commit comments