git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] bisect: avoid signed integer overflow

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 2, 2013, 21:09 UTC
Message-ID
<7vzjxgabd6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<0cb4456948b0874a1cedc5679a7b23b82e755e94.1364931627.git.john@keeping.me.uk>
John Keeping <john@keeping.me.uk> writes:
Show 16 quoted lines
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---
>  bisect.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/bisect.c b/bisect.c
> index bd1b7b5..0d33c6f 100644
> --- a/bisect.c
> +++ b/bisect.c
> @@ -526,7 +526,7 @@ struct commit_list *filter_skipped(struct commit_list *list,
>   * for this application.
>   */
>  static int get_prn(int count) {
> -	count = count * 1103515245 + 12345;
> +	count = ((unsigned) count) * 1103515245 + 12345;
>  	return ((unsigned)(count/65536) % PRN_MODULO);
I wonder
	static int get_prn(unsigned);
or even
	static unsigned get_prn(unsigned);
to lose the existing cast may be a better alternative.
Previous: John KeepingNext: John Keeping
Message 8 of 9 in “Fixes for undefined behaviour”
  1. 0/2 Fixes for undefined behaviourJohn Keeping, Apr 2, 2013
  2. 1/2 diffcore-break: don't divide by zeroJohn Keeping, Apr 2, 2013
  3. Junio C HamanoApr 2, 2013
  4. John KeepingApr 2, 2013
  5. Junio C HamanoApr 2, 2013
  6. diffcore-break: don't divide by zeroJohn Keeping, Apr 3, 2013
  7. 2/2 bisect: avoid signed integer overflowJohn Keeping, Apr 2, 2013
  8. Junio C HamanoApr 2, 2013
  9. John KeepingApr 3, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.