Skip to content

Commit ad4d079

Browse files
cmake: Fix build errors and warnings
The rework addresses multiple build errors and warnings encountered under strict compilation flags (e.g., -Werror). The following issues were resolved: - Pointer type errors in gzflush calls are now wrapped in #ifdef DLT_LOGSTORAGE_USE_GZIP to ensure correct compilation when GZIP support is enabled. - String truncation and buffer overflow warnings in logstorage path and filename handling are fixed by using snprintf and proper length checks. - The inline keyword was removed from the declaration of dlt_user_is_logLevel_enabled to match its definition and resolve unused inline warnings. - The node_id buffer in passive node control is now properly null-terminated after strncpy to prevent truncation warnings. - The argument order for calloc in dlt-example-user.c was corrected to avoid transposed-args warnings. Signed-off-by: lum3hc <[email protected]>
1 parent 27683d3 commit ad4d079

25 files changed

+223
-211
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ add_compile_options(
241241
# -pedantic
242242
-Wno-variadic-macros
243243
-Wno-strict-aliasing
244+
-Werror
244245
)
245246

246247
if(WITH_DOC STREQUAL "OFF")

include/dlt/dlt_client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(
116116
* @param verbose if set to true verbose information is printed out.
117117
* @return negative value if there was an error
118118
*/
119-
int dlt_client_init_port(DltClient *client, int port, int verbose);
119+
DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose);
120120

121121
/**
122122
* Initialising dlt client structure
@@ -196,7 +196,7 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct
196196
* @param client pointer to dlt client structure
197197
* @return negative value if there was an error
198198
*/
199-
int dlt_client_get_log_info(DltClient *client);
199+
DltReturnValue dlt_client_get_log_info(DltClient *client);
200200
/**
201201
* Send an request to get default log level to the dlt daemon
202202
* @param client pointer to dlt client structure
@@ -208,7 +208,7 @@ DltReturnValue dlt_client_get_default_log_level(DltClient *client);
208208
* @param client pointer to dlt client structure
209209
* @return negative value if there was an error
210210
*/
211-
int dlt_client_get_software_version(DltClient *client);
211+
DltReturnValue dlt_client_get_software_version(DltClient *client);
212212
/**
213213
* Initialise get log info structure
214214
* @return void

include/dlt/dlt_multiple_files.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char
139139
/**
140140
* Creates filename with index.
141141
* @param files_buffer pointer to MultipleFilesRingBuffer struct.
142-
* @param length the maximum length of the log_file_name.
143142
* @param idx index to be used for file name creation.
144143
*/
145-
void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, size_t length, unsigned int idx);
144+
void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, unsigned int idx);
146145

147146
/**
148147
* Generates index for log file name.

include/dlt/dlt_user.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ DltReturnValue dlt_user_log_resend_buffer(void);
12621262
* @param loglevel this is the current log level of the log message to be sent
12631263
* @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is enabled
12641264
*/
1265-
inline DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle, DltLogLevelType loglevel);
1265+
DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle, DltLogLevelType loglevel);
12661266

12671267

12681268
# ifdef DLT_TEST_ENABLE

src/console/dlt-passive-node-ctrl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void set_node_id(char *id)
113113
exit(-1);
114114
}
115115
else {
116-
strncpy(g_options.node_id, id, DLT_ID_SIZE);
116+
strncpy(g_options.node_id, id, DLT_ID_SIZE - 1);
117+
g_options.node_id[DLT_ID_SIZE - 1] = '\0';
117118
}
118119
}
119120

src/daemon/dlt-daemon.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
# endif
6262
#endif
6363

64+
#include <getopt.h>
65+
#ifndef CONFIGURATION_FILES_DIR
66+
#define CONFIGURATION_FILES_DIR "/etc"
67+
#endif
68+
#ifndef DLT_USER_IPC_PATH
69+
#define DLT_USER_IPC_PATH "/tmp"
70+
#endif
71+
6472
#include "dlt_types.h"
6573
#include "dlt-daemon.h"
6674
#include "dlt-daemon_cfg.h"
@@ -204,7 +212,7 @@ void usage()
204212
printf("Options:\n");
205213
printf(" -d Daemonize\n");
206214
printf(" -h Usage\n");
207-
printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n");
215+
printf(" -c filename DLT daemon configuration file (Default: %s/dlt.conf)\n", CONFIGURATION_FILES_DIR);
208216

209217
#ifdef DLT_DAEMON_USE_FIFO_IPC
210218
printf(" -t directory Directory for local fifo and user-pipes (Default: /tmp)\n");
@@ -363,10 +371,18 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
363371
/* switch() */
364372

365373
#ifdef DLT_DAEMON_USE_FIFO_IPC
366-
snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
367-
"%s/dltpipes", dltFifoBaseDir);
368-
snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
369-
"%s/dlt", dltFifoBaseDir);
374+
if (strlen(dltFifoBaseDir) + strlen("/dltpipes") < DLT_PATH_MAX) {
375+
snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
376+
"%s/dltpipes", dltFifoBaseDir);
377+
} else {
378+
daemon_local->flags.userPipesDir[0] = '\0';
379+
}
380+
if (strlen(dltFifoBaseDir) + strlen("/dlt") < DLT_PATH_MAX) {
381+
snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
382+
"%s/dlt", dltFifoBaseDir);
383+
} else {
384+
daemon_local->flags.daemonFifoName[0] = '\0';
385+
}
370386
#endif
371387

372388
#ifdef DLT_SHM_ENABLE
@@ -407,7 +423,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
407423
#else /* DLT_DAEMON_USE_FIFO_IPC */
408424
n = snprintf(daemon_local->flags.loggingFilename,
409425
sizeof(daemon_local->flags.loggingFilename),
410-
"%s/dlt.log", dltFifoBaseDir);
426+
"%s/dlt.log", DLT_USER_IPC_PATH);
411427
#endif
412428

413429
if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) {
@@ -1309,7 +1325,7 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca
13091325
}
13101326
#endif
13111327

1312-
static int dlt_mkdir_recursive(const char *dir)
1328+
int dlt_mkdir_recursive(const char *dir)
13131329
{
13141330
int ret = 0;
13151331
char tmp[PATH_MAX + 1];
@@ -1464,21 +1480,17 @@ int main(int argc, char *argv[])
14641480
PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag);
14651481

14661482
/* Make sure the parent user directory is created */
1483+
const char *dir_to_create;
14671484
#ifdef DLT_DAEMON_USE_FIFO_IPC
1468-
1469-
if (dlt_mkdir_recursive(dltFifoBaseDir) != 0) {
1470-
dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", dltFifoBaseDir);
1471-
return -1;
1472-
}
1473-
1485+
dir_to_create = dltFifoBaseDir;
14741486
#else
1475-
if (dlt_mkdir_recursive(DLT_USER_IPC_PATH) != 0) {
1476-
dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", daemon_local.flags.appSockPath);
1487+
dir_to_create = DLT_USER_IPC_PATH;
1488+
#endif
1489+
if (dlt_mkdir_recursive(dir_to_create) != 0) {
1490+
dlt_vlog(LOG_ERR, "Base dir %s cannot be created!\n", dir_to_create);
14771491
return -1;
14781492
}
14791493

1480-
#endif
1481-
14821494
/* --- Daemon init phase 1 begin --- */
14831495
if (dlt_daemon_local_init_p1(&daemon, &daemon_local, daemon_local.flags.vflag) == -1) {
14841496
dlt_log(LOG_CRIT, "Initialization of phase 1 failed!\n");

src/daemon/dlt_daemon_common.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,15 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
720720
#endif
721721
#ifdef DLT_DAEMON_USE_FIFO_IPC
722722
if (dlt_user_handle < DLT_FD_MINIMUM) {
723-
snprintf(filename,
724-
DLT_DAEMON_COMMON_TEXTBUFSIZE,
725-
"%s/dltpipes/dlt%d",
726-
dltFifoBaseDir,
727-
pid);
723+
if (strlen(dltFifoBaseDir) + strlen("/dltpipes/dlt") + 11 < DLT_DAEMON_COMMON_TEXTBUFSIZE) { // 11 for max pid digits
724+
snprintf(filename,
725+
DLT_DAEMON_COMMON_TEXTBUFSIZE,
726+
"%s/dltpipes/dlt%d",
727+
dltFifoBaseDir,
728+
pid);
729+
} else {
730+
filename[0] = '\0';
731+
}
728732

729733
dlt_user_handle = open(filename, O_WRONLY | O_NONBLOCK);
730734

src/examples/dlt-example-user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ int main(int argc, char *argv[])
270270
message = argv[index];
271271
}
272272
else { /* allocate raw buffer */
273-
message = calloc(sizeof(char), rvalue);
273+
message = calloc(rvalue, sizeof(char));
274274
memset(message, 'X', rvalue - 1);
275275
}
276276

src/gateway/dlt_gateway.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,9 +1608,9 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
16081608
return DLT_RETURN_OK;
16091609
}
16101610

1611-
int dlt_gateway_process_on_demand_request(DltGateway *gateway,
1611+
DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *gateway,
16121612
DltDaemonLocal *daemon_local,
1613-
char node_id[DLT_ID_SIZE],
1613+
char *node_id,
16141614
int connection_status,
16151615
int verbose)
16161616
{

src/gateway/dlt_gateway.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *g, int fd);
112112
* @param verbose verbose flag
113113
* @return 0 on success, -1 otherwise
114114
*/
115-
int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
115+
DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
116116
DltDaemonLocal *daemon_local,
117117
DltReceiver *recv,
118118
int verbose);
@@ -157,7 +157,7 @@ int dlt_gateway_forward_control_message(DltGateway *g,
157157
* @param verbose verbose flag
158158
* @return 0 on success, -1 otherwise
159159
*/
160-
int dlt_gateway_process_on_demand_request(DltGateway *g,
160+
DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *g,
161161
DltDaemonLocal *daemon_local,
162162
char *node_id,
163163
int connection_status,

0 commit comments

Comments
 (0)