Skip to content

Commit 9e940b0

Browse files
committed
Issue 107 - Avoid Signed integer overflows.
1 parent ee2805a commit 9e940b0

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

demod_9600.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ inline static void nudge_pll (int chan, int subchan, int slice, float demod_out_
491491
*/
492492

493493
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
494-
D->slicer[slice].data_clock_pll += D->pll_step_per_sample;
494+
495+
// Perform the add as unsigned to avoid signed overflow error.
496+
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
495497

496498
if ( D->slicer[slice].prev_d_c_pll > 1000000000 && D->slicer[slice].data_clock_pll < -1000000000) {
497499

demod_afsk.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,9 @@ inline static void nudge_pll (int chan, int subchan, int slice, int demod_data,
11221122
*/
11231123

11241124
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
1125-
D->slicer[slice].data_clock_pll += D->pll_step_per_sample;
1125+
1126+
// Perform the add as unsigned to avoid signed overflow error.
1127+
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
11261128

11271129
//text_color_set(DW_COLOR_DEBUG);
11281130
// dw_printf ("prev = %lx, new data clock pll = %lx\n" D->prev_d_c_pll, D->data_clock_pll);

demod_psk.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ inline static void nudge_pll (int chan, int subchan, int slice, int demod_bits,
794794

795795
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
796796

797-
D->slicer[slice].data_clock_pll += D->pll_step_per_sample;
797+
// Perform the add as unsigned to avoid signed overflow error.
798+
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
798799

799800
if (D->slicer[slice].data_clock_pll < 0 && D->slicer[slice].prev_d_c_pll >= 0) {
800801

gen_packets.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
static int seed = 1;
8585

8686
static int my_rand (void) {
87-
seed = ((seed * 1103515245) + 12345) & MY_RAND_MAX;
87+
// Perform the calculation as unsigned to avoid signed overflow error.
88+
seed = (int)(((unsigned)seed * 1103515245) + 12345) & MY_RAND_MAX;
8889
return (seed);
8990
}
9091

0 commit comments

Comments
 (0)