Commit 824d2b47 authored by frtabu's avatar frtabu

new set of cppcheck fixes

parent 63143b87
// suppress error about keysP not free, it is done by calling func */ // suppress error about keysP memory leak, free must be done by calling func */
memleak:common/utils/hashtable/obj_hashtable.c memleak:
common/utils/hashtable/obj_hashtable.c
// suppress error about keys memory leak, free must be done by calling func */
memleak:
openair2/UTIL/OMG/omg_hashtable.c
// followings errors are in file not used in oai exec's included in CI // followings errors are in file not used in oai exec's included in CI
invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/ltetest.c invalidPrintfArgType_sint:
memleak:openair1/PHY/CODING/TESTBENCH/ltetest.c openair1/PHY/CODING/TESTBENCH/ltetest.c
invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/pdcch_test.c memleak:
openair1/PHY/CODING/TESTBENCH/ltetest.c
invalidPrintfArgType_sint:
openair1/PHY/CODING/TESTBENCH/pdcch_test.c
This diff is collapsed.
...@@ -5,46 +5,41 @@ ...@@ -5,46 +5,41 @@
#include <string.h> #include <string.h>
unsigned long register_notifier(gui *_g, char *notification, widget *w, unsigned long register_notifier(gui *_g, char *notification, widget *w,
notifier handler, void *private) notifier handler, void *private) {
{
struct gui *g = _g; struct gui *g = _g;
unsigned long ret; unsigned long ret;
glock(g); glock(g);
if (g->next_notifier_id == 2UL * 1024 * 1024 * 1024) if (g->next_notifier_id == 2UL * 1024 * 1024 * 1024)
ERR("%s:%d: report a bug\n", __FILE__, __LINE__); ERR("%s:%d: report a bug\n", __FILE__, __LINE__);
g->notifiers = realloc(g->notifiers, g->notifiers = realloc(g->notifiers,
(g->notifiers_count+1) * sizeof(struct notifier)); (g->notifiers_count+1) * sizeof(struct notifier));
if (g->notifiers == NULL) abort(); if (g->notifiers == NULL) abort();
ret = g->next_notifier_id; ret = g->next_notifier_id;
g->notifiers[g->notifiers_count].handler = handler; g->notifiers[g->notifiers_count].handler = handler;
g->notifiers[g->notifiers_count].id = g->next_notifier_id; g->notifiers[g->notifiers_count].id = g->next_notifier_id;
g->next_notifier_id++; g->next_notifier_id++;
g->notifiers[g->notifiers_count].notification = strdup(notification); g->notifiers[g->notifiers_count].notification = strdup(notification);
if (g->notifiers[g->notifiers_count].notification == NULL) abort(); if (g->notifiers[g->notifiers_count].notification == NULL) abort();
g->notifiers[g->notifiers_count].w = w; g->notifiers[g->notifiers_count].w = w;
g->notifiers[g->notifiers_count].private = private; g->notifiers[g->notifiers_count].private = private;
/* initialize done to 1 so as not to call the handler if it's created /* initialize done to 1 so as not to call the handler if it's created
* by the call of another one that is in progress * by the call of another one that is in progress
*/ */
g->notifiers[g->notifiers_count].done = 1; g->notifiers[g->notifiers_count].done = 1;
g->notifiers_count++; g->notifiers_count++;
gunlock(g); gunlock(g);
return ret; return ret;
} }
void unregister_notifier(gui *_g, unsigned long notifier_id) void unregister_notifier(gui *_g, unsigned long notifier_id) {
{
struct gui *g = _g; struct gui *g = _g;
int i; int i;
glock(g); glock(g);
for (i = 0; i < g->notifiers_count; i++) for (i = 0; i < g->notifiers_count; i++)
...@@ -54,13 +49,12 @@ void unregister_notifier(gui *_g, unsigned long notifier_id) ...@@ -54,13 +49,12 @@ void unregister_notifier(gui *_g, unsigned long notifier_id)
ERR("%s:%d: notifier_id %ld not found\n", __FILE__,__LINE__,notifier_id); ERR("%s:%d: notifier_id %ld not found\n", __FILE__,__LINE__,notifier_id);
free(g->notifiers[i].notification); free(g->notifiers[i].notification);
memmove(g->notifiers + i, g->notifiers + i + 1, memmove(g->notifiers + i, g->notifiers + i + 1,
(g->notifiers_count-1 - i) * sizeof(struct notifier)); (g->notifiers_count-1 - i) * sizeof(struct notifier));
g->notifiers_count--; g->notifiers_count--;
g->notifiers = realloc(g->notifiers, g->notifiers = realloc(g->notifiers,
g->notifiers_count * sizeof(struct notifier)); g->notifiers_count * sizeof(struct notifier));
if (g->notifiers == NULL) abort(); if (g->notifiers == NULL) abort();
gunlock(g); gunlock(g);
...@@ -68,19 +62,19 @@ void unregister_notifier(gui *_g, unsigned long notifier_id) ...@@ -68,19 +62,19 @@ void unregister_notifier(gui *_g, unsigned long notifier_id)
/* called with lock ON */ /* called with lock ON */
void gui_notify(struct gui *g, char *notification, widget *w, void gui_notify(struct gui *g, char *notification, widget *w,
void *notification_data) void *notification_data) {
{
void *private; void *private;
notifier handler; notifier handler;
int i; int i;
/* this function is not re-entrant, for the moment keep as is /* this function is not re-entrant, for the moment keep as is
* and if the need is there, we'll make a new thread to handle * and if the need is there, we'll make a new thread to handle
* notifications (or something) * notifications (or something)
* for now let's crash in case of recursive call * for now let's crash in case of recursive call
*/ */
static int inside = 0; static int inside = 0;
if (inside) ERR("%s:%d: BUG! contact the authors\n", __FILE__, __LINE__); if (inside) ERR("%s:%d: BUG! contact the authors\n", __FILE__, __LINE__);
inside = 1; inside = 1;
/* clear all handlers */ /* clear all handlers */
...@@ -91,26 +85,25 @@ void gui_notify(struct gui *g, char *notification, widget *w, ...@@ -91,26 +85,25 @@ void gui_notify(struct gui *g, char *notification, widget *w,
* need to be careful here * need to be careful here
*/ */
loop: loop:
for (i = 0; i < g->notifiers_count; i++) { for (i = 0; i < g->notifiers_count; i++) {
if (g->notifiers[i].done == 1 || if (g->notifiers[i].done == 1 ||
g->notifiers[i].w != w || g->notifiers[i].w != w ||
strcmp(g->notifiers[i].notification, notification) != 0) strcmp(g->notifiers[i].notification, notification) != 0)
continue; continue;
break; break;
} }
if (i == g->notifiers_count) goto done; if (i == g->notifiers_count) goto done;
g->notifiers[i].done = 1; g->notifiers[i].done = 1;
handler = g->notifiers[i].handler; handler = g->notifiers[i].handler;
private = g->notifiers[i].private; private = g->notifiers[i].private;
gunlock(g); gunlock(g);
handler(private, g, notification, w, notification_data); handler(private, g, notification, w, notification_data);
glock(g); glock(g);
goto loop; goto loop;
done: done:
inside = 0; inside = 0;
} }
...@@ -7,21 +7,19 @@ ...@@ -7,21 +7,19 @@
#include "config.h" #include "config.h"
#include "../T_defs.h" #include "../T_defs.h"
void usage(void) void usage(void) {
{
printf( printf(
"options:\n" "options:\n"
" -d <database file> this option is mandatory\n" " -d <database file> this option is mandatory\n"
" -ip <host> connect to given IP address (default %s)\n" " -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n", " -p <port> connect to given port (default %d)\n",
DEFAULT_REMOTE_IP, DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT DEFAULT_REMOTE_PORT
); );
exit(1); exit(1);
} }
int main(int n, char **v) int main(int n, char **v) {
{
char *database_filename = NULL; char *database_filename = NULL;
void *database; void *database;
char *ip = DEFAULT_REMOTE_IP; char *ip = DEFAULT_REMOTE_IP;
...@@ -36,11 +34,28 @@ int main(int n, char **v) ...@@ -36,11 +34,28 @@ int main(int n, char **v)
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; } if (!strcmp(v[i], "-d")) {
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; } if (i > n-2) usage();
if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; } database_filename = v[++i];
continue;
}
if (!strcmp(v[i], "-ip")) {
if (i > n-2) usage();
ip = v[++i];
continue;
}
if (!strcmp(v[i], "-p")) {
if (i > n-2) usage();
port = atoi(v[++i]);
continue;
}
usage(); usage();
} }
...@@ -50,71 +65,92 @@ int main(int n, char **v) ...@@ -50,71 +65,92 @@ int main(int n, char **v)
} }
database = parse_database(database_filename); database = parse_database(database_filename);
load_config_file(database_filename); load_config_file(database_filename);
number_of_events = number_of_ids(database); number_of_events = number_of_ids(database);
is_on = calloc(number_of_events, sizeof(int)); is_on = calloc(number_of_events, sizeof(int));
if (is_on == NULL) abort(); if (is_on == NULL) abort();
on_off(database, "ENB_PHY_INPUT_SIGNAL", is_on, 1); on_off(database, "ENB_PHY_INPUT_SIGNAL", is_on, 1);
on_off(database, "ENB_PHY_ULSCH_UE_NACK", is_on, 1); on_off(database, "ENB_PHY_ULSCH_UE_NACK", is_on, 1);
on_off(database, "ENB_PHY_ULSCH_UE_ACK", is_on, 1); on_off(database, "ENB_PHY_ULSCH_UE_ACK", is_on, 1);
ev_input = event_id_from_name(database, "ENB_PHY_INPUT_SIGNAL"); ev_input = event_id_from_name(database, "ENB_PHY_INPUT_SIGNAL");
ev_nack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_NACK"); ev_nack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_NACK");
ev_ack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_ACK"); ev_ack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_ACK");
socket = connect_to(ip, port); socket = connect_to(ip, port);
t = 1; t = 1;
if (socket_send(socket, &t, 1) == -1 || if (socket_send(socket, &t, 1) == -1 ||
socket_send(socket, &number_of_events, sizeof(int)) == -1 || socket_send(socket, &number_of_events, sizeof(int)) == -1 ||
socket_send(socket, is_on, number_of_events * sizeof(int)) == -1) socket_send(socket, is_on, number_of_events * sizeof(int)) == -1)
abort(); abort();
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
char dump[10][T_BUFFER_MAX]; char dump[10][T_BUFFER_MAX];
event dump_ev[10]; event dump_ev[10];
FILE *z = fopen("/tmp/dd", "w"); if (z == NULL) abort(); FILE *z = fopen("/tmp/dd", "w");
if (z == NULL) abort();
while (1) { while (1) {
char *v; char *v;
event e; event e;
e = get_event(socket, &ebuf, database); e = get_event(socket, &ebuf, database);
v = ebuf.obuf; v = ebuf.obuf;
if (e.type == -1) break; if (e.type == -1) break;
if (e.type == ev_input) { if (e.type == ev_input) {
int sf = e.e[2].i; int sf = e.e[2].i;
if (ebuf.osize > T_BUFFER_MAX)
{ printf("event size too big\n"); exit(1); } if (ebuf.osize > T_BUFFER_MAX) {
printf("event size too big\n");
exit(1);
}
memcpy(dump[sf], ebuf.obuf, ebuf.osize); memcpy(dump[sf], ebuf.obuf, ebuf.osize);
dump_ev[sf] = e; dump_ev[sf] = e;
printf("input %d/%d\n", e.e[1].i, sf); printf("input %d/%d\n", e.e[1].i, sf);
if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort();
fflush(z); if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort();
fflush(z);
} }
if (e.type == ev_nack) { if (e.type == ev_nack) {
int sf = e.e[2].i; int sf = e.e[2].i;
printf("nack %d/%d\n", e.e[1].i, sf); printf("nack %d/%d\n", e.e[1].i, sf);
FILE *f = fopen("/tmp/dump.raw", "w"); if (f == NULL) abort(); FILE *f = fopen("/tmp/dump.raw", "w");
if (f == NULL) abort();
if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v), if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v),
dump_ev[sf].e[4].bsize, 1, f) != 1) abort(); dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
if (fclose(f)) abort(); if (fclose(f)) abort();
printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v)); printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v));
// getchar(); // getchar();
} }
if (e.type == ev_ack) { if (e.type == ev_ack) {
int sf = e.e[2].i; int sf = e.e[2].i;
printf("ack %d/%d\n", e.e[1].i, sf); printf("ack %d/%d\n", e.e[1].i, sf);
FILE *f = fopen("/tmp/dump.raw", "w"); if (f == NULL) abort(); FILE *f = fopen("/tmp/dump.raw", "w");
if (f == NULL) abort();
if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v), if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v),
dump_ev[sf].e[4].bsize, 1, f) != 1) abort(); dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
if (fclose(f)) abort(); if (fclose(f)) abort();
printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v)); printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v));
// getchar(); // getchar();
} }
} }
if (z)
fclose(z);
return 0; return 0;
} }
This diff is collapsed.
...@@ -9,27 +9,38 @@ ...@@ -9,27 +9,38 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <math.h> #include <math.h>
void new_thread(void *(*f)(void *), void *data) void new_thread(void *(*f)(void *), void *data) {
{
pthread_t t; pthread_t t;
pthread_attr_t att; pthread_attr_t att;
if (pthread_attr_init(&att)) if (pthread_attr_init(&att)) {
{ fprintf(stderr, "pthread_attr_init err\n"); exit(1); } fprintf(stderr, "pthread_attr_init err\n");
if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) exit(1);
{ fprintf(stderr, "pthread_attr_setdetachstate err\n"); exit(1); } }
if (pthread_attr_setstacksize(&att, 10000000))
{ fprintf(stderr, "pthread_attr_setstacksize err\n"); exit(1); } if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
if (pthread_create(&t, &att, f, data)) fprintf(stderr, "pthread_attr_setdetachstate err\n");
{ fprintf(stderr, "pthread_create err\n"); exit(1); } exit(1);
if (pthread_attr_destroy(&att)) }
{ fprintf(stderr, "pthread_attr_destroy err\n"); exit(1); }
if (pthread_attr_setstacksize(&att, 10000000)) {
fprintf(stderr, "pthread_attr_setstacksize err\n");
exit(1);
}
if (pthread_create(&t, &att, f, data)) {
fprintf(stderr, "pthread_create err\n");
exit(1);
}
if (pthread_attr_destroy(&att)) {
fprintf(stderr, "pthread_attr_destroy err\n");
exit(1);
}
} }
void sleepms(int ms) void sleepms(int ms) {
{
struct timespec t; struct timespec t;
t.tv_sec = ms / 1000; t.tv_sec = ms / 1000;
t.tv_nsec = (ms % 1000) * 1000000L; t.tv_nsec = (ms % 1000) * 1000000L;
...@@ -37,12 +48,15 @@ void sleepms(int ms) ...@@ -37,12 +48,15 @@ void sleepms(int ms)
if (nanosleep(&t, NULL)) abort(); if (nanosleep(&t, NULL)) abort();
} }
void bps(char *out, float v, char *suffix) void bps(char *out, float v, char *suffix) {
{
static char *bps_unit[4] = { "", "k", "M", "G" }; static char *bps_unit[4] = { "", "k", "M", "G" };
int flog; int flog;
if (v < 1000) flog = 0; else flog = floor(floor(log10(v)) / 3);
if (v < 1000) flog = 0;
else flog = floor(floor(log10(v)) / 3);
if (flog > 3) flog = 3; if (flog > 3) flog = 3;
v /= pow(10, flog*3); v /= pow(10, flog*3);
sprintf(out, "%g%s%s", round(v*100)/100, bps_unit[flog], suffix); sprintf(out, "%g%s%s", round(v*100)/100, bps_unit[flog], suffix);
} }
...@@ -51,25 +65,31 @@ void bps(char *out, float v, char *suffix) ...@@ -51,25 +65,31 @@ void bps(char *out, float v, char *suffix)
/* list */ /* list */
/****************************************************************************/ /****************************************************************************/
list *list_remove_head(list *l) list *list_remove_head(list *l) {
{
list *ret; list *ret;
if (l == NULL) return NULL; if (l == NULL) return NULL;
ret = l->next; ret = l->next;
if (ret != NULL) ret->last = l->last; if (ret != NULL) ret->last = l->last;
free(l); free(l);
return ret; return ret;
} }
list *list_append(list *l, void *data) list *list_append(list *l, void *data) {
{
list *new = calloc(1, sizeof(list)); list *new = calloc(1, sizeof(list));
if (new == NULL) abort(); if (new == NULL) abort();
new->data = data; new->data = data;
if (l == NULL) { if (l == NULL) {
new->last = new; new->last = new;
return new; return new;
} }
l->last->next = new; l->last->next = new;
l->last = new; l->last = new;
return l; return l;
...@@ -79,88 +99,107 @@ list *list_append(list *l, void *data) ...@@ -79,88 +99,107 @@ list *list_append(list *l, void *data)
/* socket */ /* socket */
/****************************************************************************/ /****************************************************************************/
int create_listen_socket(char *addr, int port) int create_listen_socket(char *addr, int port) {
{
struct sockaddr_in a; struct sockaddr_in a;
int s; int s;
int v; int v;
s = socket(AF_INET, SOCK_STREAM, 0); s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) { perror("socket"); exit(1); }
if (s == -1) {
perror("socket");
exit(1);
}
v = 1; v = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int)))
{ perror("setsockopt"); exit(1); } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int))) {
perror("setsockopt");
exit(1);
}
a.sin_family = AF_INET; a.sin_family = AF_INET;
a.sin_port = htons(port); a.sin_port = htons(port);
a.sin_addr.s_addr = inet_addr(addr); a.sin_addr.s_addr = inet_addr(addr);
if (bind(s, (struct sockaddr *)&a, sizeof(a))) { perror("bind"); exit(1); } if (bind(s, (struct sockaddr *)&a, sizeof(a))) {
if (listen(s, 5)) { perror("listen"); exit(1); } perror("bind");
exit(1);
}
if (listen(s, 5)) {
perror("listen");
exit(1);
}
return s; return s;
} }
int socket_accept(int s) int socket_accept(int s) {
{
struct sockaddr_in a; struct sockaddr_in a;
socklen_t alen; socklen_t alen;
alen = sizeof(a); alen = sizeof(a);
return accept(s, (struct sockaddr *)&a, &alen); return accept(s, (struct sockaddr *)&a, &alen);
} }
int socket_send(int socket, void *buffer, int size) int socket_send(int socket, void *buffer, int size) {
{
char *x = buffer; char *x = buffer;
int ret; int ret;
while (size) { while (size) {
ret = write(socket, x, size); ret = write(socket, x, size);
if (ret <= 0) return -1; if (ret <= 0) return -1;
size -= ret; size -= ret;
x += ret; x += ret;
} }
return 0; return 0;
} }
int get_connection(char *addr, int port) int get_connection(char *addr, int port) {
{
int s, t; int s, t;
printf("waiting for connection on %s:%d\n", addr, port); printf("