Re: [GSOC][PATCH] apply: address -Wsign-comparison warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 13 2025 07:08:13 +0100, Patrick Steinhardt wrote,
> > @@ -2706,7 +2707,7 @@ static int find_pos(struct apply_state *state,
> >  {
> >  	int i;
> >  	unsigned long backwards, forwards, current;
> > -	int backwards_lno, forwards_lno, current_lno;
> > +	size_t backwards_lno, forwards_lno, current_lno;
> >  
> >  	/*
> >  	 * When running with --allow-overlap, it is possible that a hunk is
> 
> These are a bit curious, as they store `line`, which is itself an `int`
> parameter. As far as I understand, the only caller is also only ever
> passing a positive integer here.

They do store an `int` parameter, which is `line`. However, we cannot change 
`line` to unsigned since it can temporarily store an negative value before 
the assignments to these `*_lno` happen. Below are from function `find_pos` 
(without any change).

  /*
   * If match_beginning or match_end is specified, there is no
   * point starting from a wrong line that will never match and
   * wander around and wait for a match at the specified end.
   */
  if (match_beginning)
	  line = 0;
  else if (match_end)
	  line = img->line_nr - preimage->line_nr;

  /*
   * Because the comparison is unsigned, the following test
   * will also take care of a negative line number that can
   * result when match_end and preimage is larger than the target.
   */
  if (line > img->line_nr)
	  line = img->line_nr;

> > @@ -4288,19 +4289,19 @@ static void summary_patch_list(struct patch *patch)
> >  
> >  static void patch_stats(struct apply_state *state, struct patch *patch)
> >  {
> > -	int lines = patch->lines_added + patch->lines_deleted;
> > +	unsigned lines = patch->lines_added + patch->lines_deleted;
> 
> This one is curious again, as the type of these variables is an `int`.
> This should likely be adapted in tandem if they cannot be negative.

Thank you for identifying. Will be in next version.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux