Fix x86 compilation error using GCC 9

This commit is contained in:
Amin Ben Ramdhane 2021-05-25 00:14:44 +01:00 committed by Omar Kallel
parent f73a82a126
commit faaedd342f
5 changed files with 23 additions and 17 deletions

View file

@ -272,7 +272,7 @@ int cwmp_uci_get_value_common(char *cmd, char **value, bool state)
return CWMP_GEN_ERR;
}
if (state) {
strncpy(state_path, VARSTATE_CONFIG, strlen(VARSTATE_CONFIG));
CWMP_STRNCPY(state_path, VARSTATE_CONFIG, sizeof(state_path));
uci_add_delta_path(c, c->savedir);
uci_set_savedir(c, state_path);
}
@ -351,7 +351,7 @@ int uci_set_value(char *path, char *value, uci_config_action action)
}
if (action == CWMP_CMD_SET_STATE) {
strncpy(state_path, VARSTATE_CONFIG, strlen(VARSTATE_CONFIG));
CWMP_STRNCPY(state_path, VARSTATE_CONFIG, sizeof(state_path));
uci_add_delta_path(c, c->savedir);
uci_set_savedir(c, state_path);
}

4
http.c
View file

@ -220,7 +220,7 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
if (ip && ip[0] != '\0') {
if (ip_acs[0] == '\0' || strcmp(ip_acs, ip) != 0) {
strncpy(ip_acs, ip, strlen(ip));
CWMP_STRNCPY(ip_acs, ip, sizeof(ip_acs));
if (cwmp->conf.ipv6_enable) {
tmp = inet_pton(AF_INET, ip, buf);
if (tmp == 1)
@ -307,7 +307,7 @@ static void http_cr_new_client(int client, bool service_available)
method_is_get = true;
if (!strncasecmp(buffer, "Authorization: Digest ", strlen("Authorization: Digest "))) {
auth_digest_checked = true;
strncpy(auth_digest_buffer, buffer, strlen(buffer));
CWMP_STRNCPY(auth_digest_buffer, buffer, BUFSIZ);
}
if (buffer[0] == '\r' || buffer[0] == '\n') {

View file

@ -512,4 +512,10 @@ void icwmp_cleanmem();
} while (0)
#endif
#define CWMP_STRNCPY(DST, SRC, SIZE) \
do { \
strncpy(DST, SRC, SIZE-1); \
DST[SIZE-1] = '\0'; \
} while(0)
#endif

10
log.c
View file

@ -42,9 +42,9 @@ int log_set_severity_idx(char *value)
int log_set_log_file_name(char *value)
{
if (value != NULL) {
strncpy(log_file_name, value, strlen(value));
CWMP_STRNCPY(log_file_name, value, sizeof(log_file_name));
} else {
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
CWMP_STRNCPY(log_file_name, DEFAULT_LOG_FILE_NAME, sizeof(log_file_name));
}
return 1;
}
@ -121,7 +121,7 @@ void puts_log(int severity, const char *fmt, ...)
Tm = localtime(&tv.tv_sec);
i = snprintf(buf, sizeof(buf), "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
if (strlen(log_file_name) == 0) {
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
CWMP_STRNCPY(log_file_name, DEFAULT_LOG_FILE_NAME, sizeof(log_file_name));
}
if (enable_log_file) {
if (stat(log_file_name, &st) == 0) {
@ -138,7 +138,7 @@ void puts_log(int severity, const char *fmt, ...)
va_start(args, fmt);
i += vsprintf(buf + i, (const char *)fmt, args);
if (enable_log_file) {
strncpy(buf_file, buf, strlen(buf));
CWMP_STRNCPY(buf_file, buf, sizeof(buf_file));
buf_file[strlen(buf)] = '\n';
buf_file[strlen(buf) + 1] = '\0';
fputs(buf_file, pLog);
@ -184,7 +184,7 @@ void puts_log_xmlmsg(int severity, char *msg, int msgtype)
Tm = localtime(&tv.tv_sec);
snprintf(buf, sizeof(buf), "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
if (strlen(log_file_name) == 0) {
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
CWMP_STRNCPY(log_file_name, DEFAULT_LOG_FILE_NAME, sizeof(log_file_name));
}
if (msgtype == XML_MSG_IN) {

16
xml.c
View file

@ -654,18 +654,18 @@ error:
char *xml_get_cwmp_version(int version)
{
static char versions[60];
unsigned pos = 0;
int k;
char tmp[15] = "";
static char versions[60] = "";
versions[0] = '\0';
versions[0] = '\0';
for (k = 0; k < version; k++) {
if (k == 0)
sprintf(tmp, "1.%d", k);
else
sprintf(tmp, ", 1.%d", k);
strncat(versions, tmp, strlen(tmp));
pos += snprintf(&versions[pos], sizeof(versions) - pos, "1.%d, ", k);
}
if (pos)
versions[pos - 2] = 0;
return versions;
}