From 9a46b042c57144c26a67781d335e6ba4128382d2 Mon Sep 17 00:00:00 2001 From: srs5694 Date: Tue, 15 Mar 2011 00:34:10 -0400 Subject: Patches supplied by Florian Zumbiehl --- sgdisk.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'sgdisk.cc') diff --git a/sgdisk.cc b/sgdisk.cc index 11df6ed..1f3e792 100644 --- a/sgdisk.cc +++ b/sgdisk.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -438,6 +439,7 @@ int BuildMBR(GPTData & theGPT, char* argument, int isHybrid) { if ((&theGPT != NULL) && (argument != NULL)) { numParts = CountColons(argument) + 1; + cout << "numParts = " << numParts << "\n"; if (numParts <= (4 - isHybrid)) { newMBR.SetDisk(theGPT.GetDisk()); for (i = 0; i < numParts; i++) { @@ -464,15 +466,14 @@ int BuildMBR(GPTData & theGPT, char* argument, int isHybrid) { return allOK; } // BuildMBR() -// Returns the number of colons in argument string +// Returns the number of colons in argument string, ignoring the +// first character (thus, a leading colon is ignored, as GetString() +// does). int CountColons(char* argument) { - int num = 0, i = 0; + int num = 0; + + while ((argument[0] != '\0') && (argument = strchr(&argument[1], ':'))) + num++; - if (argument != NULL) { - while (argument[i] != '\0') { - if (argument[i++] == ':') - num++; - } // while - } // if return num; } // CountColons() -- cgit v1.2.1