Skip to content

Commit

Permalink
[clang-tidy] Fix bugprone string compare
Browse files Browse the repository at this point in the history
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb authored and nikias committed Apr 22, 2022
1 parent 95316d8 commit c461e6d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/afc.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t
}

/* check if it's a valid AFC header */
if (strncmp(header.magic, AFC_MAGIC, AFC_MAGIC_LEN)) {
if (strncmp(header.magic, AFC_MAGIC, AFC_MAGIC_LEN) != 0) {
debug_info("Invalid AFC packet received (magic != " AFC_MAGIC ")!");
}

Expand Down
8 changes: 4 additions & 4 deletions src/device_link_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static int device_link_service_get_message(plist_t dl_msg, char **message)
return 0;
}

if ((strlen(cmd_str) < 9) || (strncmp(cmd_str, "DL", 2))) {
if ((strlen(cmd_str) < 9) || (strncmp(cmd_str, "DL", 2) != 0)) {
free(cmd_str);
return 0;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ device_link_service_error_t device_link_service_version_exchange(device_link_ser
goto leave;
}
device_link_service_get_message(array, &msg);
if (!msg || strcmp(msg, "DLMessageVersionExchange")) {
if (!msg || strcmp(msg, "DLMessageVersionExchange") != 0) {
debug_info("Did not receive DLMessageVersionExchange from device!");
err = DEVICE_LINK_SERVICE_E_PLIST_ERROR;
goto leave;
Expand Down Expand Up @@ -239,7 +239,7 @@ device_link_service_error_t device_link_service_version_exchange(device_link_ser
goto leave;
}
device_link_service_get_message(array, &msg);
if (!msg || strcmp(msg, "DLMessageDeviceReady")) {
if (!msg || strcmp(msg, "DLMessageDeviceReady") != 0) {
debug_info("Did not get DLMessageDeviceReady!");
err = DEVICE_LINK_SERVICE_E_PLIST_ERROR;
goto leave;
Expand Down Expand Up @@ -403,7 +403,7 @@ device_link_service_error_t device_link_service_receive_process_message(device_l

char *msg = NULL;
device_link_service_get_message(pmsg, &msg);
if (!msg || strcmp(msg, "DLMessageProcessMessage")) {
if (!msg || strcmp(msg, "DLMessageProcessMessage") != 0) {
debug_info("Did not receive DLMessageProcessMessage as expected!");
err = DEVICE_LINK_SERVICE_E_PLIST_ERROR;
goto leave;
Expand Down
2 changes: 1 addition & 1 deletion src/file_relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ LIBIMOBILEDEVICE_API file_relay_error_t file_relay_request_sources_timeout(file_
goto leave;
}

if (strcmp(ack, "Acknowledged")) {
if (strcmp(ack, "Acknowledged") != 0) {
debug_info("ERROR: Did not receive 'Acknowledged' but '%s'", ack);
goto leave;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lockdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
ret = lockdownd_query_type(client_loc, &type);
if (LOCKDOWN_E_SUCCESS != ret) {
debug_info("QueryType failed in the lockdownd client.");
} else if (strcmp("com.apple.mobile.lockdown", type)) {
} else if (strcmp("com.apple.mobile.lockdown", type) != 0) {
debug_info("Warning QueryType request returned \"%s\".", type);
}
free(type);
Expand Down
2 changes: 1 addition & 1 deletion src/mobilesync.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_clear_all_records_on_device(m
goto out;
}

if (strcmp(response_type, "SDMessageDeviceWillClearAllRecords")) {
if (strcmp(response_type, "SDMessageDeviceWillClearAllRecords") != 0) {
err = MOBILESYNC_E_PLIST_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion src/screenshotr.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_take_screenshot(screenshotr
plist_t node = plist_dict_get_item(dict, "MessageType");
char *strval = NULL;
plist_get_string_val(node, &strval);
if (!strval || strcmp(strval, "ScreenShotReply")) {
if (!strval || strcmp(strval, "ScreenShotReply") != 0) {
debug_info("invalid screenshot data received!");
res = SCREENSHOTR_E_PLIST_ERROR;
goto leave;
Expand Down
4 changes: 2 additions & 2 deletions tools/idevicebackup.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ static int mobilebackup_check_file_integrity(const char *backup_directory, const
for ( i = 0; i < 20; i++, p += 2 ) {
snprintf (p, 3, "%02x", (unsigned char)fnhash[i] );
}
if (strcmp(fnamehash, hash)) {
if (strcmp(fnamehash, hash) != 0) {
printf("\r\n");
printf("WARNING: filename hash does not match for entry '%s'\n", hash);
}
Expand All @@ -544,7 +544,7 @@ static int mobilebackup_check_file_integrity(const char *backup_directory, const
plist_get_string_val(node, &auth_version);
}

if (strcmp(auth_version, "1.0")) {
if (strcmp(auth_version, "1.0") != 0) {
printf("\r\n");
printf("WARNING: Unknown AuthVersion '%s', DataHash cannot be verified!\n", auth_version);
}
Expand Down
16 changes: 8 additions & 8 deletions tools/idevicedebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
goto cleanup;
}
Expand All @@ -423,7 +423,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
goto cleanup;
}
Expand All @@ -439,7 +439,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
goto cleanup;
}
Expand Down Expand Up @@ -480,7 +480,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
goto cleanup;
}
Expand Down Expand Up @@ -514,7 +514,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
goto cleanup;
}
Expand All @@ -540,7 +540,7 @@ int main(int argc, char *argv[])

if (response) {
log_debug("response: %s", response);
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
dres = debugserver_client_handle_response(debugserver_client, &response, &res);
if (dres != DEBUGSERVER_E_SUCCESS) {
log_debug("failed to process response; error %d; %s", dres, response);
Expand All @@ -567,7 +567,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
}
free(response);
Expand All @@ -581,7 +581,7 @@ int main(int argc, char *argv[])
debugserver_command_free(command);
command = NULL;
if (response) {
if (strncmp(response, "OK", 2)) {
if (strncmp(response, "OK", 2) != NULL) {
debugserver_client_handle_response(debugserver_client, &response, NULL);
}
free(response);
Expand Down
2 changes: 1 addition & 1 deletion tools/idevicepair.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int main(int argc, char **argv)
result = EXIT_FAILURE;
goto leave;
} else {
if (strcmp("com.apple.mobile.lockdown", type)) {
if (strcmp("com.apple.mobile.lockdown", type) != 0) {
printf("WARNING: QueryType request returned '%s'\n", type);
}
free(type);
Expand Down

0 comments on commit c461e6d

Please sign in to comment.