Issue 107 - Avoid Signed integer overflows.

This commit is contained in:
wb2osz 2017-07-30 21:43:29 -04:00
parent ee2805a307
commit 9e940b0b5a
4 changed files with 10 additions and 4 deletions

View File

@ -491,7 +491,9 @@ inline static void nudge_pll (int chan, int subchan, int slice, float demod_out_
*/ */
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll; D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
D->slicer[slice].data_clock_pll += D->pll_step_per_sample;
// Perform the add as unsigned to avoid signed overflow error.
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
if ( D->slicer[slice].prev_d_c_pll > 1000000000 && D->slicer[slice].data_clock_pll < -1000000000) { if ( D->slicer[slice].prev_d_c_pll > 1000000000 && D->slicer[slice].data_clock_pll < -1000000000) {

View File

@ -1122,7 +1122,9 @@ inline static void nudge_pll (int chan, int subchan, int slice, int demod_data,
*/ */
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll; D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
D->slicer[slice].data_clock_pll += D->pll_step_per_sample;
// Perform the add as unsigned to avoid signed overflow error.
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
//text_color_set(DW_COLOR_DEBUG); //text_color_set(DW_COLOR_DEBUG);
// dw_printf ("prev = %lx, new data clock pll = %lx\n" D->prev_d_c_pll, D->data_clock_pll); // dw_printf ("prev = %lx, new data clock pll = %lx\n" D->prev_d_c_pll, D->data_clock_pll);

View File

@ -794,7 +794,8 @@ inline static void nudge_pll (int chan, int subchan, int slice, int demod_bits,
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll; D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
D->slicer[slice].data_clock_pll += D->pll_step_per_sample; // Perform the add as unsigned to avoid signed overflow error.
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
if (D->slicer[slice].data_clock_pll < 0 && D->slicer[slice].prev_d_c_pll >= 0) { if (D->slicer[slice].data_clock_pll < 0 && D->slicer[slice].prev_d_c_pll >= 0) {

View File

@ -84,7 +84,8 @@
static int seed = 1; static int seed = 1;
static int my_rand (void) { static int my_rand (void) {
seed = ((seed * 1103515245) + 12345) & MY_RAND_MAX; // Perform the calculation as unsigned to avoid signed overflow error.
seed = (int)(((unsigned)seed * 1103515245) + 12345) & MY_RAND_MAX;
return (seed); return (seed);
} }