mirror of https://github.com/wb2osz/direwolf.git
Issue 107 - Avoid Signed integer overflows.
This commit is contained in:
parent
ee2805a307
commit
9e940b0b5a
|
@ -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].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) {
|
||||
|
||||
|
|
|
@ -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].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);
|
||||
// dw_printf ("prev = %lx, new data clock pll = %lx\n" D->prev_d_c_pll, D->data_clock_pll);
|
||||
|
|
|
@ -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].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) {
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@
|
|||
static int seed = 1;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue