@@ -267,21 +267,20 @@ static int show_file(const char *arg, int output_prefix)
267267
268268static int try_difference (const char * arg )
269269{
270- char * dotdot ;
270+ const char * dotdot ;
271271 struct object_id start_oid ;
272272 struct object_id end_oid ;
273273 const char * end ;
274274 const char * start ;
275+ char * to_free ;
275276 int symmetric ;
276277 static const char head_by_default [] = "HEAD" ;
277278
278279 if (!(dotdot = strstr (arg , ".." )))
279280 return 0 ;
281+ start = to_free = xmemdupz (arg , dotdot - arg );
280282 end = dotdot + 2 ;
281- start = arg ;
282283 symmetric = (* end == '.' );
283-
284- * dotdot = 0 ;
285284 end += symmetric ;
286285
287286 if (!* end )
@@ -295,7 +294,7 @@ static int try_difference(const char *arg)
295294 * Just ".."? That is not a range but the
296295 * pathspec for the parent directory.
297296 */
298- * dotdot = '.' ;
297+ free ( to_free ) ;
299298 return 0 ;
300299 }
301300
@@ -308,7 +307,7 @@ static int try_difference(const char *arg)
308307 a = lookup_commit_reference (the_repository , & start_oid );
309308 b = lookup_commit_reference (the_repository , & end_oid );
310309 if (!a || !b ) {
311- * dotdot = '.' ;
310+ free ( to_free ) ;
312311 return 0 ;
313312 }
314313 if (repo_get_merge_bases (the_repository , a , b , & exclude ) < 0 )
@@ -318,55 +317,56 @@ static int try_difference(const char *arg)
318317 show_rev (REVERSED , & commit -> object .oid , NULL );
319318 }
320319 }
321- * dotdot = '.' ;
320+ free ( to_free ) ;
322321 return 1 ;
323322 }
324- * dotdot = '.' ;
323+ free ( to_free ) ;
325324 return 0 ;
326325}
327326
328327static int try_parent_shorthands (const char * arg )
329328{
330- char * dotdot ;
329+ const char * mark ;
331330 struct object_id oid ;
332331 struct commit * commit ;
333332 struct commit_list * parents ;
334333 int parent_number ;
335334 int include_rev = 0 ;
336335 int include_parents = 0 ;
337336 int exclude_parent = 0 ;
337+ char * to_free ;
338338
339- if ((dotdot = strstr (arg , "^!" ))) {
339+ if ((mark = strstr (arg , "^!" ))) {
340340 include_rev = 1 ;
341- if (dotdot [2 ])
341+ if (mark [2 ])
342342 return 0 ;
343- } else if ((dotdot = strstr (arg , "^@" ))) {
343+ } else if ((mark = strstr (arg , "^@" ))) {
344344 include_parents = 1 ;
345- if (dotdot [2 ])
345+ if (mark [2 ])
346346 return 0 ;
347- } else if ((dotdot = strstr (arg , "^-" ))) {
347+ } else if ((mark = strstr (arg , "^-" ))) {
348348 include_rev = 1 ;
349349 exclude_parent = 1 ;
350350
351- if (dotdot [2 ]) {
351+ if (mark [2 ]) {
352352 char * end ;
353- exclude_parent = strtoul (dotdot + 2 , & end , 10 );
353+ exclude_parent = strtoul (mark + 2 , & end , 10 );
354354 if (* end != '\0' || !exclude_parent )
355355 return 0 ;
356356 }
357357 } else
358358 return 0 ;
359359
360- * dotdot = 0 ;
360+ arg = to_free = xmemdupz ( arg , mark - arg ) ;
361361 if (repo_get_oid_committish (the_repository , arg , & oid ) ||
362362 !(commit = lookup_commit_reference (the_repository , & oid ))) {
363- * dotdot = '^' ;
363+ free ( to_free ) ;
364364 return 0 ;
365365 }
366366
367367 if (exclude_parent &&
368368 exclude_parent > commit_list_count (commit -> parents )) {
369- * dotdot = '^' ;
369+ free ( to_free ) ;
370370 return 0 ;
371371 }
372372
@@ -387,7 +387,7 @@ static int try_parent_shorthands(const char *arg)
387387 free (name );
388388 }
389389
390- * dotdot = '^' ;
390+ free ( to_free ) ;
391391 return 1 ;
392392}
393393
0 commit comments