MA-11241 [Android] Use strlen() to calculate the string length
authorLuo Ji <ji.luo@nxp.com>
Thu, 25 Jan 2018 06:48:23 +0000 (14:48 +0800)
committerLuo Ji <ji.luo@nxp.com>
Thu, 25 Jan 2018 11:38:54 +0000 (19:38 +0800)
Calculate the string length with strlen() instead of hard code.

Change-Id: I6028c249ca03f5d3d08225c528d3584e507c64b3
Signed-off-by: Luo Ji <ji.luo@nxp.com>
drivers/usb/gadget/f_fastboot.c

index 9eb7fb6..fa3d9cb 100755 (executable)
@@ -2787,28 +2787,33 @@ static void cb_flashing(struct usb_ep *ep, struct usb_request *req)
                    FASTBOOT_BOOTLOADER_VBOOT_KEY,
                    strlen(FASTBOOT_BOOTLOADER_VBOOT_KEY))) {
                strcpy(response, "OKAY");
-       } else if (!strncmp(cmd + len - 15, "unlock_critical", 15)) {
+       } else if (!strncmp(cmd + len - strlen("unlock_critical"),
+                               "unlock_critical", strlen("unlock_critical"))) {
 #else
-       if (!strncmp(cmd + len - 15, "unlock_critical", 15)) {
+       if (!strncmp(cmd + len - strlen("unlock_critical"),
+                               "unlock_critical", strlen("unlock_critical"))) {
 #endif
                strcpy(response, "OKAY");
-       } else if (!strncmp(cmd + len - 13, "lock_critical", 13)) {
+       } else if (!strncmp(cmd + len - strlen("lock_critical"),
+                               "lock_critical", strlen("lock_critical"))) {
                strcpy(response, "OKAY");
-       } else if (!strncmp(cmd + len - 6, "unlock", 6)) {
+       } else if (!strncmp(cmd + len - strlen("unlock"),
+                               "unlock", strlen("unlock"))) {
                printf("flashing unlock.\n");
                status = do_fastboot_unlock(false);
                if (status != FASTBOOT_LOCK_ERROR)
                        strcpy(response, "OKAY");
                else
                        strcpy(response, "FAIL unlock device failed.");
-       } else if (!strncmp(cmd + len - 4, "lock", 4)) {
+       } else if (!strncmp(cmd + len - strlen("lock"), "lock", strlen("lock"))) {
                printf("flashing lock.\n");
                status = do_fastboot_lock();
                if (status != FASTBOOT_LOCK_ERROR)
                        strcpy(response, "OKAY");
                else
                        strcpy(response, "FAIL lock device failed.");
-       } else if (!strncmp(cmd + len - 18, "get_unlock_ability", 18)) {
+       } else if (!strncmp(cmd + len - strlen("get_unlock_ability"),
+                               "get_unlock_ability", strlen("get_unlock_ability"))) {
                result = fastboot_lock_enable();
                if (result == FASTBOOT_UL_ENABLE) {
                        fastboot_tx_write_more("INFO1");