fix some cppchecker warnings, missing null checks, consts

This commit is contained in:
iceman1001
2025-09-02 22:27:45 +02:00
parent 0929a14b5d
commit d3627920cd
8 changed files with 51 additions and 14 deletions
+13 -8
View File
@@ -43,11 +43,15 @@ static void mqtt_publish_callback(void **unused, struct mqtt_response_publish *p
// note that published->topic_name is NOT null-terminated (here we'll change it to a c-string)
char *topic_name = (char *) calloc(published->topic_name_size + 1, 1);
if (topic_name == NULL) {
return;
}
memcpy(topic_name, published->topic_name, published->topic_name_size);
const char *msg = published->application_message;
char *ps = strstr(msg, "Created\": \"proxmark3");
const char *ps = strstr(msg, "Created\": \"proxmark3");
if (ps) {
int res = saveFileTXT("ice_mqtt", ".json", msg, published->application_message_size, spDefault);
if (res == PM3_SUCCESS) {
@@ -68,7 +72,8 @@ static void *mqtt_client_refresher(void *client) {
}
return NULL;
}
static int mqtt_exit(int status, mqtt_pal_socket_handle sockfd, pthread_t *client_daemon) {
static int mqtt_exit(int status, mqtt_pal_socket_handle sockfd, const pthread_t *client_daemon) {
close_nb_socket(sockfd);
if (client_daemon != NULL) {
mqtt_client_should_exit = 1;
@@ -277,15 +282,15 @@ static int CmdMqttSend(const char *Cmd) {
int plen = 0;
char port[10 + 1] = {0x00};
res = CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)port, sizeof(port), &plen);
res |= CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)port, sizeof(port), &plen);
int tlen = 0;
char topic[128] = {0x00};
res = CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)topic, sizeof(topic), &tlen);
res |= CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)topic, sizeof(topic), &tlen);
int mlen = 0;
char msg[128] = {0x00};
res = CLIParamStrToBuf(arg_get_str(ctx, 4), (uint8_t *)msg, sizeof(msg), &mlen);
res |= CLIParamStrToBuf(arg_get_str(ctx, 4), (uint8_t *)msg, sizeof(msg), &mlen);
int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
@@ -358,11 +363,11 @@ static int CmdMqttReceive(const char *Cmd) {
int plen = 0;
char port[10 + 1] = {0x00};
res = CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)port, sizeof(port), &plen);
res |= CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)port, sizeof(port), &plen);
int tlen = 0;
char topic[128] = {0x00};
res = CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)topic, sizeof(topic), &tlen);
res |= CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)topic, sizeof(topic), &tlen);
int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
@@ -419,4 +424,4 @@ static int CmdHelp(const char *Cmd) {
int CmdMqtt(const char *Cmd) {
clearCommandBuffer();
return CmdsParse(CommandTable, Cmd);
}
}
+1 -1
View File
@@ -3171,7 +3171,7 @@ int searchFile(char **foundpath, const char *pm3dir, const char *searchname, con
* Returns PM3_SUCCES or, PM3_EFILE;
*
* @param filepath Path to the file.
* @param line Line to insert (should not contain a trailing newline).
* @param keystr Line to insert (should not contain a trailing newline).
*/
int insert_line_if_not_exists(const char *preferredName, const char *keystr) {
+2 -2
View File
@@ -426,8 +426,8 @@ int pm3_save_fm11rf08s_nonces(const char *fn, iso14a_fm11rf08s_nonces_with_data_
* Returns PM3_SUCCES or, PM3_EFILE;
*
* @param filepath Path to the file.
* @param line Line to insert (should not contain a trailing newline).
* @param keystr Line to insert (should not contain a trailing newline).
*/
int insert_line_if_not_exists(const char *preferredName, const char *line);
int insert_line_if_not_exists(const char *preferredName, const char *keystr);
#endif // FILEUTILS_H
+22
View File
@@ -784,6 +784,9 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
length = ((sizeof(graphText)) + (sizeof(uint32_t) * 3) + sizeof(scalestr) + sizeof(float_t));
annotation = (char *)calloc(1, length);
if (annotation == NULL) {
return;
}
snprintf(annotation, length, graphText,
g_GraphStart,
@@ -805,6 +808,9 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
length = (sizeof(gridText) + (sizeof(double) * 3) + sizeof(gridLocked));
annotation = (char *)calloc(1, length);
if (annotation == NULL) {
return;
}
snprintf(annotation, length, gridText,
g_DefaultGridX,
@@ -831,7 +837,14 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
size_t value;
annotation = (char *)calloc(1, length);
if (annotation == NULL) {
return;
}
char *textA = (char *)calloc(1, length);
if (textA == NULL) {
return;
}
strcat(textA, markerText);
strcat(textA, " (%s%u)");
@@ -863,6 +876,9 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
pos = g_MarkerB.pos;
annotation = (char *)calloc(1, length);
if (annotation == NULL) {
return;
}
snprintf(annotation, length, markerText,
"B",
@@ -880,6 +896,9 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
pos = g_MarkerC.pos;
annotation = (char *)calloc(1, length);
if (annotation == NULL) {
return;
}
snprintf(annotation, length, markerText,
"C",
@@ -897,6 +916,9 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
pos = g_MarkerD.pos;
annotation = (char *)calloc(1, length);
if (annotation == NULL) {
return;
}
snprintf(annotation, length, markerText,
"D",
+10
View File
@@ -635,10 +635,20 @@ static void set_my_executable_path(void) {
}
my_executable_path = (char *)calloc(path_length + 1, sizeof(uint8_t));
if (my_executable_path == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return;
}
int dirname_length = 0;
if (wai_getExecutablePath(my_executable_path, path_length, &dirname_length) != -1) {
my_executable_path[path_length] = '\0';
my_executable_directory = (char *)calloc(dirname_length + 2, sizeof(uint8_t));
if (my_executable_path == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
return;
}
strncpy(my_executable_directory, my_executable_path, dirname_length + 1);
my_executable_directory[dirname_length + 1] = '\0';
}
+1 -1
View File
@@ -333,7 +333,7 @@ int main(int argc, char *argv[]) {
// read in nR aR pairs
numnrar = 0;
buf = (char *)calloc(1, lenbuf);
if (!buf) {
if (buf == NULL) {
printf("cannot calloc buf\n");
exit(1);
}
+1 -1
View File
@@ -266,7 +266,7 @@ static void init_guess_table(char *filename, char *uidstr) {
num_nRaR = 0;
buf = (char *)calloc(1, lenbuf);
if (!buf) {
if (buf == NULL) {
printf("cannot calloc buf\n");
exit(1);
}
@@ -262,7 +262,7 @@ int main(int argc, char *argv[]) {
}
ctx.kernelSource = (char *)calloc(1, filestat.st_size);
if (!ctx.kernelSource) {
if (ctx.kernelSource == NULL) {
printf("Cannot calloc kernelSource\n");
exit(1);
}