From 5e942fea311902818c14576f5aaaed71bf1d3fe0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 12 Nov 2015 07:28:39 -0800 Subject: [PATCH] Cope with angler's whitespace-padded partition size reporting. Before: $ fastboot -w wiping userdata... Couldn't parse partition size '0x 0x66257ee00'. wiping cache... Couldn't parse partition size '0x 0x6400000'. erasing 'userdata'... Bug: http://b/25653580 (cherry picked from commit a2db2618ecd9e96cb0b00d05a7f357c8b4b5fc62) Change-Id: I15e6bee4d88695d4482013c4f86586276acdea84 --- fastboot/fastboot.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index c8f66d701..42e47a6c0 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -1027,6 +1027,11 @@ static void fb_perform_format(usb_handle* usb, } partition_size = size_override; } + // Some bootloaders (angler, for example), send spurious leading whitespace. + partition_size = android::base::Trim(partition_size); + // Some bootloaders (hammerhead, for example) use implicit hex. + // This code used to use strtol with base 16. + if (!android::base::StartsWith(partition_size, "0x")) partition_size = "0x" + partition_size; gen = fs_get_generator(partition_type); if (!gen) { @@ -1040,10 +1045,6 @@ static void fb_perform_format(usb_handle* usb, return; } - // Some bootloaders (hammerhead, for example) use implicit hex. - // This code used to use strtol with base 16. - if (!android::base::StartsWith(partition_size, "0x")) partition_size = "0x" + partition_size; - int64_t size; if (!android::base::ParseInt(partition_size.c_str(), &size)) { fprintf(stderr, "Couldn't parse partition size '%s'.\n", partition_size.c_str());