Limit the profile sample count to INT_MAX to avoid both signed
overflow and a potential division by zero when updating the stored
mean value.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
#include <stdint.h>
#include <stdio.h>
#include <strings.h>
+#include <limits.h>
#include <assert.h>
#include <ipxe/isqrt.h>
#include <ipxe/profile.h>
*/
assert ( ( ( signed ) sample ) >= 0 );
- /* Update sample count */
- profiler->count++;
+ /* Update sample count, limiting to avoid signed overflow */
+ if ( profiler->count < INT_MAX )
+ profiler->count++;
/* Adjust mean sample value scale if necessary. Skip if
* sample is zero (in which case flsl(sample)-1 would