Skip to content

Conversation

jerryzj
Copy link
Contributor

@jerryzj jerryzj commented Aug 29, 2025

…rithmetic

UBSan reports signed overflow in several hash computations in MultiSource/Applications/lemon/lemon.c:

  • strhash: h = h*13 + *x (line ~4174)
  • statehash: h = h571 + a->rp->index37 + a->dot (line ~4557)
  • confighash: h = h571 + a->rp->index37 + a->dot (line ~4715)
  • datatype hash: hash = hash*53 + stddt[j] (line ~3409)

These use intentional wraparound, but signed overflow is undefined in C. Switch accumulators to unsigned and use unsigned operations so wraparound is well-defined. No functional change is intended beyond removing UB.

…rithmetic

UBSan reports signed overflow in several hash computations in
MultiSource/Applications/lemon/lemon.c:
  - strhash: h = h*13 + *x (line ~4174)
  - statehash: h = h*571 + a->rp->index*37 + a->dot (line ~4557)
  - confighash: h = h*571 + a->rp->index*37 + a->dot (line ~4715)
  - datatype hash: hash = hash*53 + stddt[j] (line ~3409)

These use intentional wraparound, but signed overflow is undefined in C.
Switch accumulators to unsigned and use unsigned operations so wraparound
is well-defined. No functional change is intended beyond removing UB.

Signed-off-by: Jerry Zhang Jian <[email protected]>
@jerryzj jerryzj requested a review from topperc August 29, 2025 03:06
@topperc topperc requested a review from nikic August 29, 2025 05:41
@@ -1238,14 +1238,14 @@ struct lemon *lemp;

/* Sort the configuration list */
void Configlist_sort(){
current = (struct config *)msort((char *)current,(char **)&(current->next),Configcmp);
current = (struct config *)msort((char *)current,(char **)&(current->next),(int(*)(const char*,const char*))Configcmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete the declaration instead of adding casts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants