Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with undefined behavior and compiler warnings #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions autotest/autotest.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ void liquid_autotest_print_array(unsigned char * _x,
#define CONTEND_DELTA_FL(F,L,X,Y,D) TEST_DELTA(F,L,#X,(X),#Y,(Y),#D,(D))
#define CONTEND_DELTA(X,Y,D) CONTEND_DELTA_FL(__FILE__,__LINE__,X,Y,D)

// CONTEND_DELTA_COMPLEX
#define TEST_DELTA_COMPLEX(F,L,EX,X,EY,Y,ED,D) \
{ \
if (cabs((X)-(Y))>(D)) \
{ \
liquid_autotest_failed_expr(F,L,"abs(" #X "-" #Y ")", \
cabs(X-Y),"<",ED,D); \
} else { \
liquid_autotest_passed(); \
} \
}
#define CONTEND_DELTA_COMPLEX_FL(F,L,X,Y,D) TEST_DELTA_COMPLEX(F,L,#X,(X),#Y,(Y),#D,(D))
#define CONTEND_DELTA_COMPLEX(X,Y,D) CONTEND_DELTA_COMPLEX_FL(__FILE__,__LINE__,X,Y,D)

// CONTEND_EXPRESSION
#define TEST_EXPRESSION(F,L,EX,X) \
{ \
Expand Down
36 changes: 18 additions & 18 deletions include/liquid.h
Original file line number Diff line number Diff line change
Expand Up @@ -1027,9 +1027,9 @@ void fec_decode_soft(fec _q,
// _fec0 : inner forward error-correction code
// _fec1 : outer forward error-correction code
unsigned int packetizer_compute_enc_msg_len(unsigned int _n,
int _crc,
int _fec0,
int _fec1);
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1);

// computes the number of decoded bytes before packetizing
//
Expand All @@ -1038,9 +1038,9 @@ unsigned int packetizer_compute_enc_msg_len(unsigned int _n,
// _fec0 : inner forward error-correction code
// _fec1 : outer forward error-correction code
unsigned int packetizer_compute_dec_msg_len(unsigned int _k,
int _crc,
int _fec0,
int _fec1);
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1);

typedef struct packetizer_s * packetizer;

Expand All @@ -1051,9 +1051,9 @@ typedef struct packetizer_s * packetizer;
// _fec0 : inner forward error-correction code
// _fec1 : outer forward error-correction code
packetizer packetizer_create(unsigned int _dec_msg_len,
int _crc,
int _fec0,
int _fec1);
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1);

// re-create packetizer object
//
Expand All @@ -1064,9 +1064,9 @@ packetizer packetizer_create(unsigned int _dec_msg_len,
// _fec1 : outer forward error-correction code
packetizer packetizer_recreate(packetizer _p,
unsigned int _dec_msg_len,
int _crc,
int _fec0,
int _fec1);
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1);

// destroy packetizer object
void packetizer_destroy(packetizer _p);
Expand Down Expand Up @@ -3774,9 +3774,9 @@ typedef struct bpacketgen_s * bpacketgen;
// _fec1 : outer forward error-correction code scheme
bpacketgen bpacketgen_create(unsigned int _m,
unsigned int _dec_msg_len,
int _crc,
int _fec0,
int _fec1);
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1);

// re-create bpacketgen object from old object
// _q : old bpacketgen object
Expand All @@ -3788,9 +3788,9 @@ bpacketgen bpacketgen_create(unsigned int _m,
bpacketgen bpacketgen_recreate(bpacketgen _q,
unsigned int _m,
unsigned int _dec_msg_len,
int _crc,
int _fec0,
int _fec1);
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1);

// destroy bpacketgen object, freeing all internally-allocated memory
void bpacketgen_destroy(bpacketgen _q);
Expand Down
2 changes: 1 addition & 1 deletion scripts/autoscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void autoscript_parsefile(autoscript _q,
char basename[1024]; // base script name
char * cptr = NULL; // readline return value
char * sptr = NULL; // tag string pointer
int cterm; // terminating character
unsigned int cterm; // terminating character
unsigned int n=0; // line number
do {
// increment line number
Expand Down
8 changes: 4 additions & 4 deletions src/dotprod/tests/dotprod_cccf_autotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void autotest_dotprod_cccf_struct_lengths()
// n = 32
dp = dotprod_cccf_create(h,32);
dotprod_cccf_execute(dp, x, &y);
CONTEND_DELTA(y, v32, tol);
CONTEND_DELTA_COMPLEX(y, v32, tol);
dotprod_cccf_destroy(dp);
if (liquid_autotest_verbose) {
printf(" dotprod-cccf-32 : %12.8f + j%12.8f (expected %12.8f + j%12.8f)\n",
Expand All @@ -144,7 +144,7 @@ void autotest_dotprod_cccf_struct_lengths()
// n = 33
dp = dotprod_cccf_create(h,33);
dotprod_cccf_execute(dp, x, &y);
CONTEND_DELTA(y, v33, tol);
CONTEND_DELTA_COMPLEX(y, v33, tol);
dotprod_cccf_destroy(dp);
if (liquid_autotest_verbose) {
printf(" dotprod-cccf-33 : %12.8f + j%12.8f (expected %12.8f + j%12.8f)\n",
Expand All @@ -154,7 +154,7 @@ void autotest_dotprod_cccf_struct_lengths()
// n = 34
dp = dotprod_cccf_create(h,34);
dotprod_cccf_execute(dp, x, &y);
CONTEND_DELTA(y, v34, tol);
CONTEND_DELTA_COMPLEX(y, v34, tol);
dotprod_cccf_destroy(dp);
if (liquid_autotest_verbose) {
printf(" dotprod-cccf-34 : %12.8f + j%12.8f (expected %12.8f + j%12.8f)\n",
Expand All @@ -164,7 +164,7 @@ void autotest_dotprod_cccf_struct_lengths()
// n = 35
dp = dotprod_cccf_create(h,35);
dotprod_cccf_execute(dp, x, &y);
CONTEND_DELTA(y, v35, tol);
CONTEND_DELTA_COMPLEX(y, v35, tol);
dotprod_cccf_destroy(dp);
if (liquid_autotest_verbose) {
printf(" dotprod-cccf-35 : %12.8f + j%12.8f (expected %12.8f + j%12.8f)\n",
Expand Down
2 changes: 2 additions & 0 deletions src/fec/src/fec.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ void fec_decode_soft(fec _q,
} else {
// pack bytes and use hard-decision decoding
unsigned enc_msg_len = fec_get_enc_msg_length(_q->scheme, _dec_msg_len);
if (enc_msg_len == 0)
return;
unsigned char msg_enc_hard[enc_msg_len];
unsigned int i;
for (i=0; i<enc_msg_len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/fec/src/fec_hamming3126.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ unsigned int fec_hamming3126_encode_symbol(unsigned int _sym_dec)
unsigned int fec_hamming3126_decode_symbol(unsigned int _sym_enc)
{
// validate input
if (_sym_enc >= (1<<31)) {
if (_sym_enc >= (1u<<31)) {
fprintf(stderr,"error, fec_hamming_decode(), input symbol too large\n");
exit(1);
}
Expand Down
26 changes: 13 additions & 13 deletions src/fec/src/packetizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void packetizer_realloc_buffers(packetizer _p, unsigned int _len);
// _fec0 : inner forward error-correction code
// _fec1 : outer forward error-correction code
unsigned int packetizer_compute_enc_msg_len(unsigned int _n,
int _crc,
int _fec0,
int _fec1)
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1)
{
unsigned int k = _n + crc_get_length(_crc);
unsigned int n0 = fec_get_enc_msg_length(_fec0, k);
Expand All @@ -58,9 +58,9 @@ unsigned int packetizer_compute_enc_msg_len(unsigned int _n,
// _fec0 : inner forward error-correction code
// _fec1 : outer forward error-correction code
unsigned int packetizer_compute_dec_msg_len(unsigned int _k,
int _crc,
int _fec0,
int _fec1)
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1)
{
unsigned int n_hat = 0;
unsigned int k_hat = 0;
Expand Down Expand Up @@ -91,9 +91,9 @@ unsigned int packetizer_compute_dec_msg_len(unsigned int _k,
// _fec0 : inner forward error-correction code
// _fec1 : outer forward error-correction code
packetizer packetizer_create(unsigned int _n,
int _crc,
int _fec0,
int _fec1)
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1)
{
packetizer p = (packetizer) malloc(sizeof(struct packetizer_s));

Expand Down Expand Up @@ -148,9 +148,9 @@ packetizer packetizer_create(unsigned int _n,
// _fec1 : outer forward error-correction code
packetizer packetizer_recreate(packetizer _p,
unsigned int _n,
int _crc,
int _fec0,
int _fec1)
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1)
{
if (_p == NULL) {
// packetizer was never created
Expand Down Expand Up @@ -389,7 +389,7 @@ int packetizer_decode_soft(packetizer _p,
key);
}

void packetizer_set_scheme(packetizer _p, int _fec0, int _fec1)
void packetizer_set_scheme(packetizer _p, fec_scheme _fec0, fec_scheme _fec1)
{
//
}
Expand Down
10 changes: 5 additions & 5 deletions src/filter/src/firdes.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,16 @@ float liquid_filter_autocorr(float * _h,
int _lag)
{
// auto-correlation is even symmetric
_lag = abs(_lag);
unsigned int _ulag = abs(_lag);

// lag outside of filter length is zero
if (_lag >= _h_len) return 0.0f;
if (_ulag >= _h_len) return 0.0f;

// compute auto-correlation
float rxx=0.0f; // initialize auto-correlation to zero
unsigned int i;
for (i=_lag; i<_h_len; i++)
rxx += _h[i] * _h[i-_lag];
for (i=_ulag; i<_h_len; i++)
rxx += _h[i] * _h[i-_ulag];

return rxx;
}
Expand Down Expand Up @@ -476,7 +476,7 @@ float liquid_filter_crosscorr(float * _h,
int n;
if (_lag < 0)
n = (int)_g_len + _lag;
else if (_lag < (_h_len-_g_len))
else if ((unsigned int)_lag < (_h_len-_g_len))
n = _g_len;
else
n = _h_len - _lag;
Expand Down
4 changes: 2 additions & 2 deletions src/filter/src/firdespm.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,11 @@ void firdespm_compute_taps(firdespm _q, float * _h)
// TODO : flesh out computation for other filter types
unsigned int j;
if (_q->btype == LIQUID_FIRDESPM_BANDPASS) {
// odd filter length, even symmetry
// even/odd filter length, even symmetry
for (i=0; i<_q->h_len; i++) {
double v = G[0];
double f = ((double)i - (double)(p-1) + 0.5*(1-_q->s)) / (double)(_q->h_len);
for (j=1; j<_q->r; j++)
for (j=1; j<p; j++)
v += 2.0 * G[j] * cos(2*M_PI*f*j);
_h[i] = v / (double)(_q->h_len);
}
Expand Down
2 changes: 1 addition & 1 deletion src/filter/src/iirdes.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void iirdes_dzpk2sosf(float complex * _zd,
float * _B,
float * _A)
{
int i;
unsigned int i;
float tol=1e-6f; // tolerance for conjuate pair computation

// find/group complex conjugate pairs (poles)
Expand Down
4 changes: 2 additions & 2 deletions src/filter/src/resamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct RESAMP(_s) {
// floating-point phase
float tau; // accumulated timing phase, 0 <= tau < 1
float bf; // soft filterbank index, bf = tau*npfb = b + mu
int b; // base filterbank index, 0 <= b < npfb
unsigned int b; // base filterbank index, 0 <= b < npfb
float mu; // fractional filterbank interpolation value, 0 <= mu < 1
TO y0; // filterbank output at index b
TO y1; // filterbank output at index b+1
Expand Down Expand Up @@ -358,7 +358,7 @@ void RESAMP(_update_timing_state)(RESAMP() _q)
_q->bf = _q->tau * (float)(_q->npfb);

// split into integer filterbank index and fractional interpolation
_q->b = (int)floorf(_q->bf); // base index
_q->b = (unsigned int)floorf(_q->bf); // base index
_q->mu = _q->bf - (float)(_q->b); // fractional index
}

4 changes: 2 additions & 2 deletions src/filter/src/symsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct SYMSYNC(_s) {
float tau; // accumulated timing phase (0 <= tau <= 1)
float tau_decim; // timing phase, retained for get_tau() method
float bf; // soft filterbank index
int b; // filterbank index
unsigned int b; // filterbank index

// loop filter
float q; // instantaneous timing error
Expand Down Expand Up @@ -504,7 +504,7 @@ void SYMSYNC(_step)(SYMSYNC() _q,
// update states
_q->tau += _q->del; // instantaneous fractional offset
_q->bf = _q->tau * (float)(_q->npfb); // filterbank index (soft)
_q->b = (int)roundf(_q->bf); // filterbank index
_q->b = (unsigned int)roundf(_q->bf); // filterbank index
n++; // number of output samples
}

Expand Down
2 changes: 1 addition & 1 deletion src/filter/tests/filter_crosscorr_autotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void autotest_filter_crosscorr_rrrf()
printf("testing corr(x,y):\n");

// corr(x,y)
int i;
unsigned int i;
for (i=0; i<rxy_len; i++) {
int lag = i - y_len + 1;
rxy[i] = liquid_filter_crosscorr(x,x_len, y,y_len, lag);
Expand Down
12 changes: 6 additions & 6 deletions src/framing/src/bpacketgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ struct bpacketgen_s {
// _fec1 : outer forward error-correction code scheme
bpacketgen bpacketgen_create(unsigned int _m,
unsigned int _dec_msg_len,
int _crc,
int _fec0,
int _fec1)
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1)
{
// validate input

Expand Down Expand Up @@ -134,9 +134,9 @@ bpacketgen bpacketgen_create(unsigned int _m,
bpacketgen bpacketgen_recreate(bpacketgen _q,
unsigned int _m,
unsigned int _dec_msg_len,
int _crc,
int _fec0,
int _fec1)
crc_scheme _crc,
fec_scheme _fec0,
fec_scheme _fec1)
{
// validate input

Expand Down
4 changes: 2 additions & 2 deletions src/framing/src/gmskframesync.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ int gmskframesync_update_symsync(gmskframesync _q,
// compute actual filterbank index
_q->pfb_index = roundf(_q->pfb_soft);

// contrain index to be in [0, npfb-1]
// constrain index to be in [0, npfb-1]
while (_q->pfb_index < 0) {
_q->pfb_index += _q->npfb;
_q->pfb_soft += _q->npfb;

// adjust pfb output timer
_q->pfb_timer--;
}
while (_q->pfb_index > _q->npfb-1) {
while ((unsigned int)_q->pfb_index > _q->npfb-1) {
_q->pfb_index -= _q->npfb;
_q->pfb_soft -= _q->npfb;

Expand Down
6 changes: 3 additions & 3 deletions src/math/src/poly.expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void POLY(_expandbinomial)(unsigned int _n,
return;
}

int i, j;
unsigned int i, j;
// initialize coefficients array to [1,0,0,....0]
for (i=0; i<=_n; i++)
_c[i] = (i==0) ? 1 : 0;
Expand Down Expand Up @@ -74,7 +74,7 @@ void POLY(_expandbinomial_pm)(unsigned int _m,
return;
}

int i, j;
unsigned int i, j;
// initialize coefficients array to [1,0,0,....0]
for (i=0; i<=n; i++)
_c[i] = (i==0) ? 1 : 0;
Expand Down Expand Up @@ -153,7 +153,7 @@ void POLY(_expandroots)(T * _a,
return;
}

int i, j;
unsigned int i, j;
// initialize coefficients array to [1,0,0,....0]
for (i=0; i<=_n; i++)
_c[i] = (i==0) ? 1 : 0;
Expand Down
Loading