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 */
memleak:common/utils/hashtable/obj_hashtable.c
// suppress error about keysP memory leak, free must be done by calling func */
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
invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/ltetest.c
memleak:openair1/PHY/CODING/TESTBENCH/ltetest.c
invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/pdcch_test.c
invalidPrintfArgType_sint:
openair1/PHY/CODING/TESTBENCH/ltetest.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 @@
#include <string.h>
unsigned long register_notifier(gui *_g, char *notification, widget *w,
notifier handler, void *private)
{
notifier handler, void *private) {
struct gui *g = _g;
unsigned long ret;
glock(g);
if (g->next_notifier_id == 2UL * 1024 * 1024 * 1024)
ERR("%s:%d: report a bug\n", __FILE__, __LINE__);
g->notifiers = realloc(g->notifiers,
(g->notifiers_count+1) * sizeof(struct notifier));
(g->notifiers_count+1) * sizeof(struct notifier));
if (g->notifiers == NULL) abort();
ret = g->next_notifier_id;
g->notifiers[g->notifiers_count].handler = handler;
g->notifiers[g->notifiers_count].id = g->next_notifier_id;
g->next_notifier_id++;
g->notifiers[g->notifiers_count].notification = strdup(notification);
if (g->notifiers[g->notifiers_count].notification == NULL) abort();
g->notifiers[g->notifiers_count].w = w;
g->notifiers[g->notifiers_count].private = private;
/* 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
*/
g->notifiers[g->notifiers_count].done = 1;
g->notifiers_count++;
gunlock(g);
return ret;
}
void unregister_notifier(gui *_g, unsigned long notifier_id)
{
void unregister_notifier(gui *_g, unsigned long notifier_id) {
struct gui *g = _g;
int i;
glock(g);
for (i = 0; i < g->notifiers_count; i++)
......@@ -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);
free(g->notifiers[i].notification);
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 = realloc(g->notifiers,
g->notifiers_count * sizeof(struct notifier));
g->notifiers_count * sizeof(struct notifier));
if (g->notifiers == NULL) abort();
gunlock(g);
......@@ -68,19 +62,19 @@ void unregister_notifier(gui *_g, unsigned long notifier_id)
/* called with lock ON */
void gui_notify(struct gui *g, char *notification, widget *w,
void *notification_data)
{
void *notification_data) {
void *private;
notifier handler;
int i;
/* 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
* notifications (or something)
* for now let's crash in case of recursive call
*/
static int inside = 0;
if (inside) ERR("%s:%d: BUG! contact the authors\n", __FILE__, __LINE__);
inside = 1;
/* clear all handlers */
......@@ -91,26 +85,25 @@ void gui_notify(struct gui *g, char *notification, widget *w,
* need to be careful here
*/
loop:
for (i = 0; i < g->notifiers_count; i++) {
if (g->notifiers[i].done == 1 ||
g->notifiers[i].w != w ||
strcmp(g->notifiers[i].notification, notification) != 0)
continue;
break;
}
if (i == g->notifiers_count) goto done;
g->notifiers[i].done = 1;
handler = g->notifiers[i].handler;
private = g->notifiers[i].private;
gunlock(g);
handler(private, g, notification, w, notification_data);
glock(g);
goto loop;
done:
inside = 0;
}
......@@ -7,21 +7,19 @@
#include "config.h"
#include "../T_defs.h"
void usage(void)
{
void usage(void) {
printf(
"options:\n"
" -d <database file> this option is mandatory\n"
" -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT
"options:\n"
" -d <database file> this option is mandatory\n"
" -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT
);
exit(1);
}
int main(int n, char **v)
{
int main(int n, char **v) {
char *database_filename = NULL;
void *database;
char *ip = DEFAULT_REMOTE_IP;
......@@ -36,11 +34,28 @@ int main(int n, char **v)
for (i = 1; i < n; i++) {
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], "-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; }
if (!strcmp(v[i], "-d")) {
if (i > n-2) usage();
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();
}
......@@ -50,71 +65,92 @@ int main(int n, char **v)
}
database = parse_database(database_filename);
load_config_file(database_filename);
number_of_events = number_of_ids(database);
is_on = calloc(number_of_events, sizeof(int));
if (is_on == NULL) abort();
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_ACK", is_on, 1);
ev_input = event_id_from_name(database, "ENB_PHY_INPUT_SIGNAL");
ev_nack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_NACK");
ev_ack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_ACK");
socket = connect_to(ip, port);
t = 1;
if (socket_send(socket, &t, 1) == -1 ||
socket_send(socket, &number_of_events, sizeof(int)) == -1 ||
socket_send(socket, is_on, number_of_events * sizeof(int)) == -1)
abort();
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
char dump[10][T_BUFFER_MAX];
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) {
char *v;
event e;
e = get_event(socket, &ebuf, database);
v = ebuf.obuf;
if (e.type == -1) break;
if (e.type == ev_input) {
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);
dump_ev[sf] = e;
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) {
int sf = e.e[2].i;
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),
dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
if (fclose(f)) abort();
printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v));
// getchar();
// getchar();
}
if (e.type == ev_ack) {
int sf = e.e[2].i;
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),
dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
if (fclose(f)) abort();
printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v));
// getchar();
// getchar();
}
}
if (z)
fclose(z);
return 0;
}
This diff is collapsed.
......@@ -9,27 +9,38 @@
#include <arpa/inet.h>
#include <math.h>
void new_thread(void *(*f)(void *), void *data)
{
void new_thread(void *(*f)(void *), void *data) {
pthread_t t;
pthread_attr_t att;
if (pthread_attr_init(&att))
{ fprintf(stderr, "pthread_attr_init err\n"); exit(1); }
if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED))
{ 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_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); }
if (pthread_attr_init(&att)) {
fprintf(stderr, "pthread_attr_init err\n");
exit(1);
}
if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
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_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;
t.tv_sec = ms / 1000;
t.tv_nsec = (ms % 1000) * 1000000L;
......@@ -37,12 +48,15 @@ void sleepms(int ms)
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" };
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;
v /= pow(10, flog*3);
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)
/* list */
/****************************************************************************/
list *list_remove_head(list *l)
{
list *list_remove_head(list *l) {
list *ret;
if (l == NULL) return NULL;
ret = l->next;
if (ret != NULL) ret->last = l->last;
free(l);
return ret;
}
list *list_append(list *l, void *data)
{
list *list_append(list *l, void *data) {
list *new = calloc(1, sizeof(list));
if (new == NULL) abort();
new->data = data;
if (l == NULL) {
new->last = new;
return new;
}
l->last->next = new;
l->last = new;
return l;
......@@ -79,88 +99,107 @@ list *list_append(list *l, void *data)
/* socket */
/****************************************************************************/
int create_listen_socket(char *addr, int port)
{
int create_listen_socket(char *addr, int port) {
struct sockaddr_in a;
int s;
int v;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) { perror("socket"); exit(1); }
if (s == -1) {
perror("socket");
exit(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_port = htons(port);
a.sin_addr.s_addr = inet_addr(addr);
if (bind(s, (struct sockaddr *)&a, sizeof(a))) { perror("bind"); exit(1); }
if (listen(s, 5)) { perror("listen"); exit(1); }
if (bind(s, (struct sockaddr *)&a, sizeof(a))) {
perror("bind");
exit(1);
}
if (listen(s, 5)) {
perror("listen");
exit(1);
}
return s;
}
int socket_accept(int s)
{
int socket_accept(int s) {
struct sockaddr_in a;
socklen_t alen;
alen = sizeof(a);
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;
int ret;
while (size) {
ret = write(socket, x, size);
if (ret <= 0) return -1;
size -= ret;
x += ret;
}
return 0;
}
int get_connection(char *addr, int port)
{
int get_connection(char *addr, int port) {
int s, t;
printf("waiting for connection on %s:%d\n", addr, port);
s = create_listen_socket(addr, port);
t = socket_accept(s);
if (t == -1) { perror("accept"); exit(1); }
close(s);
printf("connected\n");
if (t == -1) {
perror("accept");
exit(1);
}
close(s);
printf("connected\n");
return t;
}
int fullread(int fd, void *_buf, int count)
{
int fullread(int fd, void *_buf, int count) {
char *buf = _buf;
int ret = 0;
int l;
while (count) {
l = read(fd, buf, count);
if (l <= 0) return -1;
count -= l;
buf += l;
ret += l;
}
return ret;
}
int try_connect_to(char *addr, int port)
{
int try_connect_to(char *addr, int port) {
int s;
struct sockaddr_in a;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) { perror("socket"); exit(1); }
if (s == -1) {
perror("socket");
exit(1);
}
a.sin_family = AF_INET;
a.sin_port = htons(port);
......@@ -175,14 +214,12 @@ int try_connect_to(char *addr, int port)
return s;
}
int connect_to(char *addr, int port)
{
int connect_to(char *addr, int port) {
int s;
printf("connecting to %s:%d\n", addr, port);
again:
s = try_connect_to(addr, port);
if (s == -1) {
printf("trying again in 1s\n");
sleep(1);
......@@ -196,49 +233,45 @@ again:
/* buffer */
/****************************************************************************/
void PUTC(OBUF *o, char c)
{
void PUTC(OBUF *o, char c) {
if (o->osize == o->omaxsize) {
o->omaxsize += 512;
o->obuf = realloc(o->obuf, o->omaxsize);
if (o->obuf == NULL) abort();
}
o->obuf[o->osize] = c;
o->osize++;
}
void PUTS(OBUF *o, char *s)
{
void PUTS(OBUF *o, char *s) {
while (*s) PUTC(o, *s++);
}
static int clean(char c)
{
static int clean(char c) {
if (!isprint(c)) c = ' ';
return c;
}
void PUTS_CLEAN(OBUF *o, char *s)
{
void PUTS_CLEAN(OBUF *o, char *s) {
while (*s) PUTC(o, clean(*s++));
}
void PUTI(OBUF *o, int i)
{
void PUTI(OBUF *o, int i) {
char s[64];
sprintf(s, "%d", i);
PUTS(o, s);
}
void PUTX2(OBUF *o, int i)
{
void PUTX2(OBUF *o, int i) {
char s[64];
sprintf(s, "%2.2x", i);
PUTS(o, s);
}
void PUTUL(OBUF *o, unsigned long l)
{
void PUTUL(OBUF *o, unsigned long l) {
char s[128];
sprintf(s, "%ld", l);
PUTS(o, s);
......
This diff is collapsed.
......@@ -101,7 +101,7 @@ class phy_info
{
index = 0;
id = 0;
udp = 0;
local_port = 0;
remote_addr = 0;
remote_port = 0;
......@@ -178,6 +178,7 @@ class pnf_info
sync_mode = 0;
location_mode = 0;
location_coordinates = 0;
dl_config_timing = 0;
ul_config_timing = 0;
tx_timing = 0;
......
This diff is collapsed.
This diff is collapsed.
......@@ -95,7 +95,6 @@ void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch) {
}
free16(dlsch,sizeof(LTE_eNB_DLSCH_t));
dlsch = NULL;
}
}
......
......@@ -1960,6 +1960,10 @@ int allocate_REs_in_RB_MCH(int32_t **txdataF,
case 4: //16QAM
if (qam_table_s == NULL) {
LOG_E(PHY,"qam table pointer is NULL\n");
return -1;
}
qam16_table_offset_re = 0;
qam16_table_offset_im = 0;
......@@ -2029,7 +2033,9 @@ int allocate_REs_in_RB_MCH(int32_t **txdataF,
((int16_t *)&txdataF[4][tti_offset])[1]=qam_table_s[qam64_table_offset_im];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
break;
default:
LOG_E(PHY,"Invalid modulation order %i_n",mod_order);
break;
}
}
......
......@@ -308,7 +308,7 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
#ifdef DEBUG_PBCH
if (frame_mod4==0) {
LOG_M"pbch_e.m","pbch_e",
LOG_M("pbch_e.m","pbch_e",
eNB_pbch->pbch_e,
pbch_E,
1,
......@@ -325,7 +325,7 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
pbch_E);
#ifdef DEBUG_PBCH
if (frame_mod4==0) {