Skip to content

Commit

Permalink
#85: Fix code scanning alert - Wrong type of arguments to formatting …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
ballle98 committed Nov 13, 2023
1 parent da97aa2 commit 2880006
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions aq_programmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void aq_programmer(program_type r_type, char *args, struct aqualinkdata *aq_data
void _aq_programmer(program_type r_type, char *args, struct aqualinkdata *aq_data, bool allowOveride)
{
struct programmingThreadCtrl *programmingthread = malloc(sizeof(struct programmingThreadCtrl));

if (programmingthread == NULL) return;

/*
Seemed like a good idea to use lookuptable, but need to figure out a way to check program_type actually exists in array,
Expand Down Expand Up @@ -1128,7 +1128,7 @@ void cleanAndTerminateThread(struct programmingThreadCtrl *threadCtrl)
struct timespec elapsed;
clock_gettime(CLOCK_REALTIME, &threadCtrl->aq_data->last_active_time);
timespec_subtract(&elapsed, &threadCtrl->aq_data->last_active_time, &threadCtrl->aq_data->start_active_time);
LOG(PROG_LOG, LOG_DEBUG, "Thread %d,%p (%s) finished in %d.%03ld sec\n",
LOG(PROG_LOG, LOG_DEBUG, "Thread %d,%p (%s) finished in %ld.%03ld sec\n",
threadCtrl->aq_data->active_thread.ptype,
threadCtrl->aq_data->active_thread.thread_id,
ptypeName(threadCtrl->aq_data->active_thread.ptype),
Expand Down
4 changes: 4 additions & 0 deletions aq_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ void start_timer(struct aqualinkdata *aq_data, aqkey *button, int duration)
}*/

struct timerthread *tmthread = calloc(1, sizeof(struct timerthread));
if (tmthread == NULL) {
LOG(TIMR_LOG, LOG_ERR, "could not allocate memory for timer thread for button '%s'\n",button->name);
return;
}
tmthread->aq_data = aq_data;
tmthread->button = button;
tmthread->thread_id = 0;
Expand Down
2 changes: 1 addition & 1 deletion aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ void action_delayed_request()
}
else
{
LOG(AQUA_LOG,LOG_NOTICE, "SWG % is already %d, not changing\n", _aqualink_data.unactioned.value);
LOG(AQUA_LOG,LOG_NOTICE, "SWG %% is already %d, not changing\n", _aqualink_data.unactioned.value);
}
}
// Let's just tell everyone we set it, before we actually did. Makes homekit happy, and it will re-correct on error.
Expand Down
53 changes: 25 additions & 28 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ struct tmpPanelInfo {
bool dual;
};

struct tmpPanelInfo *_tmpPanel;
static struct tmpPanelInfo *_tmpPanel = NULL;

/*
* initialize data to default values
*/
void init_parameters (struct aqconfig * parms)
{
// Set default panel if it get's missed from config
_tmpPanel = malloc(sizeof(struct tmpPanelInfo));
_tmpPanel->size = 8;
_tmpPanel->rs = true;
_tmpPanel->combo = true;
_tmpPanel->dual = false;
if ((_tmpPanel = malloc(sizeof(struct tmpPanelInfo))) != NULL) {
_tmpPanel->size = 8;
_tmpPanel->rs = true;
_tmpPanel->combo = true;
_tmpPanel->dual = false;
}

clearDebugLogMask();

Expand Down Expand Up @@ -163,9 +164,10 @@ char *cleanalloc(char*str)
char *result;
str = cleanwhitespace(str);

result = (char*)malloc(strlen(str)+1);
strcpy ( result, str );
//printf("Result=%s\n",result);
if ((result = (char*)malloc(strlen(str)+1)) != NULL) {
strcpy ( result, str );
//printf("Result=%s\n",result);
}
return result;
}
/*
Expand Down Expand Up @@ -408,25 +410,25 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) {
//_config_parameters.onetouch_device_id != 0x00
rtn=true;
#endif
} else if (strncasecmp(param, "panel_type_size", 15) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "panel_type_size", 15) == 0)) {
_tmpPanel->size = strtoul(value, NULL, 10);
rtn=true;
} else if (strncasecmp(param, "panel_type_combo", 16) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "panel_type_combo", 16) == 0)) {
_tmpPanel->combo = text2bool(value);
rtn=true;
} else if (strncasecmp(param, "panel_type_dual", 15) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "panel_type_dual", 15) == 0)) {
_tmpPanel->dual = text2bool(value);
rtn=true;
} else if (strncasecmp(param, "panel_type_pda", 14) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "panel_type_pda", 14) == 0)) {
_tmpPanel->rs = !text2bool(value);
rtn=true;
} else if (strncasecmp(param, "panel_type_rs", 13) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "panel_type_rs", 13) == 0)) {
_tmpPanel->rs = text2bool(value);
rtn=true;
} else if (strncasecmp(param, "panel_type", 10) == 0) { // This must be last so it doesn't get picked up by other settings
setPanelByName(aqdata, cleanwhitespace(value));
rtn=true;
} else if (strncasecmp(param, "rs_panel_size", 13) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "rs_panel_size", 13) == 0)) {
LOG(AQUA_LOG,LOG_WARNING, "Config error, 'rs_panel_size' no longer supported, please use 'panel_type'\n");
_tmpPanel->size = strtoul(value, NULL, 10);
rtn=true;
Expand Down Expand Up @@ -502,7 +504,7 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) {
_aqconfig_.override_freeze_protect = text2bool(value);
rtn=true;
#ifdef AQ_PDA
} else if (strncasecmp(param, "pda_mode", 8) == 0) {
} else if (_tmpPanel && (strncasecmp(param, "pda_mode", 8) == 0)) {
LOG(AQUA_LOG,LOG_WARNING, "Config error, 'pda_mode' is no longer supported, please use rs_panel_type\n");
//_aqconfig_.pda_mode = text2bool(value);
//set_pda_mode(_aqconfig_.pda_mode);
Expand Down Expand Up @@ -629,9 +631,9 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) {
}
else if (strncasecmp(param, "button_", 7) == 0) {
// Check we have inichalized panel information, if not use any settings we may have
if (_aqconfig_.paneltype_mask == 0)
if (_tmpPanel && (_aqconfig_.paneltype_mask == 0)) {
setPanel(aqdata, _tmpPanel->rs, _tmpPanel->size, _tmpPanel->combo, _tmpPanel->dual);

}
int num = strtoul(param + 7, NULL, 10) - 1;
if (num > TOTAL_BUTTONS) {
LOG(AQUA_LOG,LOG_ERR, "Config error, button_%d is out of range\n",num+1);
Expand All @@ -651,9 +653,9 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) {
#endif
} else if (strncasecmp(param + 9, "_lightMode", 10) == 0) {
if (aqdata->num_lights < MAX_LIGHTS) {
int type = strtoul(value, NULL, 10);
unsigned long type = strtoul(value, NULL, 10);
if (type < LC_PROGRAMABLE || type > NUMBER_LIGHT_COLOR_TYPES) {
LOG(AQUA_LOG,LOG_ERR, "Config error, unknown light mode '%s'\n",type);
LOG(AQUA_LOG,LOG_ERR, "Config error, unknown light mode '%lu'\n",type);
} else {
aqdata->lights[aqdata->num_lights].button = &aqdata->aqbuttons[num];
aqdata->lights[aqdata->num_lights].lightType = type;
Expand Down Expand Up @@ -779,8 +781,6 @@ void read_config (struct aqualinkdata *aqdata, char *cfgFile)
//int tokenindex = 0;
char *b_ptr;



_aqconfig_.config_file = cleanalloc(cfgFile);

if( (fp = fopen(cfgFile, "r")) != NULL){
Expand All @@ -797,7 +797,8 @@ void read_config (struct aqualinkdata *aqdata, char *cfgFile)
if ( indx != NULL)
{
if ( ! setConfigValue(aqdata, b_ptr, indx+1))
LOG(AQUA_LOG,LOG_ERR, "Unknown config parameter '%.*s'\n",strlen(b_ptr)-1, b_ptr);
LOG(AQUA_LOG,LOG_ERR, "Unknown config parameter '%.*s'\n",
(int)(strlen(b_ptr)-1), b_ptr);
}
}
}
Expand All @@ -812,13 +813,9 @@ void read_config (struct aqualinkdata *aqdata, char *cfgFile)
}

free(_tmpPanel);
_tmpPanel = NULL;
}






//DEBUG_DERIAL, DEBUG, INFO, NOTICE, WARNING, ERROR
char *errorlevel2text(int level)
{
Expand Down
4 changes: 2 additions & 2 deletions iaqtouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define IAQT_MSGLEN 21

struct iaqt_page_button {
char *name[IAQT_MSGLEN];
char name[IAQT_MSGLEN];
unsigned char type; // 0x01 box, 0x08 icon wirlpool, 0x0b icon heater, 0x01 icon (main page), 0x07 light
unsigned char state;
unsigned char keycode;
Expand Down Expand Up @@ -1697,4 +1697,4 @@ Jandy To 0x60 of type Probe | HEX: 0x10|0x02|0x60|0x00|0x72|0x10|0x03|
Jandy To 0x31 of type Unknown | HEX: 0x10|0x02|0x31|0x30|0x73|0x10|0x03|
Jandy From 0x31 of type Ack | HEX: 0x10|0x02|0x00|0x01|0x00|0x00|0x13|0x10|0x03|
*/
*/
7 changes: 7 additions & 0 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -8750,6 +8750,10 @@ void mg_register_http_endpoint_opt(struct mg_connection *nc,

pd = mg_http_get_proto_data(nc);
if (pd == NULL) pd = mg_http_create_proto_data(nc);
if (pd == NULL) {
free(new_ep);
return;
}
new_ep->uri_pattern = mg_strdup(mg_mk_str(uri_path));
if (opts.auth_domain != NULL && opts.auth_file != NULL) {
new_ep->auth_domain = strdup(opts.auth_domain);
Expand Down Expand Up @@ -11539,6 +11543,9 @@ void mg_send_dns_query(struct mg_connection *nc, const char *name,
int query_type) {
struct mg_dns_message *msg =
(struct mg_dns_message *) MG_CALLOC(1, sizeof(*msg));
if (msg == NULL) {
goto cleanup;
}
struct mbuf pkt;
struct mg_dns_resource_record *rr = &msg->questions[0];

Expand Down
4 changes: 2 additions & 2 deletions net_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,10 @@ void action_mqtt_message(struct mg_connection *nc, struct mg_mqtt_message *msg)
//LOG(NET_LOG,LOG_DEBUG, "MQTT: topic %.*s %.2f\n",msg->topic.len, msg->topic.p, atof(msg->payload.p));
// If message doesn't end in set or increment we don't care about it.
if (strncmp(&msg->topic.p[msg->topic.len -4], "/set", 4) != 0 && strncmp(&msg->topic.p[msg->topic.len -10], "/increment", 10) != 0) {
LOG(NET_LOG,LOG_DEBUG, "MQTT: Ignore %.*s %.*s\n",msg->topic.len, msg->topic.p, msg->payload.len, msg->payload.p);
LOG(NET_LOG,LOG_DEBUG, "MQTT: Ignore %.*s %.*s\n",(int)(msg->topic.len), msg->topic.p, (int)(msg->payload.len), msg->payload.p);
return;
}
LOG(NET_LOG,LOG_DEBUG, "MQTT: topic %.*s %.*s\n",msg->topic.len, msg->topic.p, msg->payload.len, msg->payload.p);
LOG(NET_LOG,LOG_DEBUG, "MQTT: topic %.*s %.*s\n",(int)(msg->topic.len), msg->topic.p, (int)(msg->payload.len), msg->payload.p);

DEBUG_TIMER_START(&tid);
//Need to do this in a better manor, but for present it's ok.
Expand Down
2 changes: 1 addition & 1 deletion serial_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, boo
LOG(RSSD_LOG, LOG_ERR, "Ran out of storage, some ID's were not captured, please increase SLOG_MAX and recompile\n");

if (elapsed.tv_sec > 0) {
LOG(RSSD_LOG, LOG_NOTICE, "RS485 interface received %d packets in %d seconds (~%.2f Msg/Sec)\n", received_packets, elapsed.tv_sec, (received_packets / (float)elapsed.tv_sec) );
LOG(RSSD_LOG, LOG_NOTICE, "RS485 interface received %d packets in %ld seconds (~%.2f Msg/Sec)\n", received_packets, elapsed.tv_sec, (received_packets / (float)elapsed.tv_sec) );
}

LOG(RSSD_LOG, LOG_NOTICE, "Jandy Control Panel Model : %s\n", _panelType);
Expand Down

0 comments on commit 2880006

Please sign in to comment.