Skip to content

Conversation

@Amit-Matth
Copy link

Description:
This PR replaces the fragile 32-bit overflow detection logic in multiply_frac (in resample.c) with safer, standard 64-bit arithmetic.

Changes:

  • Implementation of multiply_frac updated to cast operands to unsigned long long before multiplication.
  • Verified overflow detection by comparing the result against UINT32_MAX.
  • Removes the complex and potentially incomplete conditional logic previously used to guess overflows.

Motivation:
The original code contained a TODO comment acknowledging the method was suboptimal: /* TODO: Could use 64 bits operation to check for overflow. But only guaranteed in C99+ */. Since modern build environments support C99/64-bit integers, this change improves code safety and maintainability, ensuring that buffer sizes for the resampler are calculated correctly without wrapping.

Related Issues: #88

@joseph-yiu
Copy link
Contributor

Thanks for this pull request.
Looks fine to me. I will ask my colleague to have a look as well.
"unsigned long long" could be more than 64-bit in some architecture but that shouldn't be an issue.
regards,
Joseph

@joseph-yiu
Copy link
Contributor

Note: my colleague highlighted that resampling is not used in AudioMark. But the fix looks fine.

@joseph-yiu
Copy link
Contributor

Merged into dev branch (dev_2026q1).

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