Refinements to new treatment of hybrid MBR and MBR conversions that
span the 2TiB boundary.
diff --git a/gpttext.cc b/gpttext.cc
index b5e8ac2..15fba7b 100644
--- a/gpttext.cc
+++ b/gpttext.cc
@@ -394,9 +394,9 @@
 // Create a hybrid MBR -- an ugly, funky thing that helps GPT work with
 // OSes that don't understand GPT.
 void GPTDataTextUI::MakeHybrid(void) {
-   uint32_t partNums[3];
+   uint32_t partNums[3] = {0, 0, 0};
    string line;
-   int numPartsToCvt = 0, i, j, mbrNum = 0;
+   int numPartsToCvt = 0, numConverted = 0, i, j, mbrNum = 0;
    unsigned int hexCode = 0;
    MBRPart hybridPart;
    MBRData hybridMBR;
@@ -418,7 +418,9 @@
    line = ReadString();
    istringstream inLine(line);
    do {
-      inLine >> partNums[numPartsToCvt++];
+      inLine >> partNums[numPartsToCvt];
+      if (partNums[numPartsToCvt] > 0)
+         numPartsToCvt++;
    } while (!inLine.eof() && (numPartsToCvt < 3));
 
    if (numPartsToCvt > 0) {
@@ -428,7 +430,7 @@
 
    for (i = 0; i < numPartsToCvt; i++) {
       j = partNums[i] - 1;
-      if (partitions[j].IsUsed() && partitions[j].IsSizedForMBR()) {
+      if (partitions[j].IsUsed() && (partitions[j].IsSizedForMBR() != MBR_SIZED_BAD)) {
          mbrNum = i + (eeFirst == 'Y');
          cout << "\nCreating entry for GPT partition #" << j + 1
               << " (MBR partition #" << mbrNum + 1 << ")\n";
@@ -441,13 +443,16 @@
          else
             hybridPart.SetStatus(0x00);
          hybridPart.SetInclusion(PRIMARY);
+         if (partitions[j].IsSizedForMBR() == MBR_SIZED_IFFY)
+            WarnAboutIffyMBRPart(j + 1);
+         numConverted++;
       } else {
          cerr << "\nGPT partition #" << j + 1 << " does not exist or is too big; skipping.\n";
       } // if/else
       hybridMBR.AddPart(mbrNum, hybridPart);
    } // for
 
-   if (numPartsToCvt > 0) { // User opted to create a hybrid MBR....
+   if (numConverted > 0) { // User opted to create a hybrid MBR....
       // Create EFI protective partition that covers the start of the disk.
       // If this location (covering the main GPT data structures) is omitted,
       // Linux won't find any partitions on the disk.
@@ -459,7 +464,7 @@
       if (eeFirst == 'Y') {
          hybridMBR.AddPart(0, hybridPart);
       } else {
-         hybridMBR.AddPart(numPartsToCvt, hybridPart);
+         hybridMBR.AddPart(numConverted, hybridPart);
       } // else
       hybridMBR.SetHybrid();
 
@@ -477,7 +482,9 @@
          } // if (GetYN() == 'Y')
       } // if unused entry
       protectiveMBR = hybridMBR;
-   } // if (numPartsToCvt > 0)
+   } else {
+      cout << "\nNo partitions converted; original protective/hybrid MBR is unmodified!\n";
+   } // if/else (numConverted > 0)
 } // GPTDataTextUI::MakeHybrid()
 
 // Convert the GPT to MBR form, storing partitions in the protectiveMBR
@@ -494,6 +501,10 @@
    protectiveMBR.EmptyMBR(0);
    for (i = 0; i < numParts; i++) {
       if (partitions[i].IsUsed()) {
+         if (partitions[i].IsSizedForMBR() == MBR_SIZED_IFFY)
+            WarnAboutIffyMBRPart(i + 1);
+         // Note: MakePart() checks for oversized partitions, so don't
+         // bother checking other IsSizedForMBR() return values....
          protectiveMBR.MakePart(i, partitions[i].GetFirstLBA(),
                                 partitions[i].GetLengthLBA(),
                                 partitions[i].GetHexType() / 0x0100, 0);
@@ -503,6 +514,24 @@
    return protectiveMBR.DoMenu();
 } // GPTDataTextUI::XFormToMBR()
 
+/******************************************************
+ *                                                    *
+ * Display informational messages for the user....    *
+ *                                                    *
+ ******************************************************/
+
+// Although an MBR partition that begins below sector 2^32 and is less than 2^32 sectors in
+// length is technically legal even if it ends above the 2^32-sector mark, such a partition
+// tends to confuse a lot of OSes, so warn the user about such partitions. This function is
+// called by XFormToMBR() and MakeHybrid(); it's a separate function just to consolidate the
+// lengthy message in one place.
+void GPTDataTextUI::WarnAboutIffyMBRPart(int partNum) {
+   cout << "\a\nWarning! GPT partition " << partNum << " ends after the 2^32 sector mark! The partition\n"
+        << "begins before this point, and is smaller than 2^32 sectors. This is technically\n"
+        << "legal, but will confuse some OSes. The partition IS being added to the MBR, but\n"
+        << "if your OS misbehaves or can't see the partition, the partition may simply be\n"
+        << "unusable in that OS and may need to be resized or omitted from the MBR.\n\n";
+} // GPTDataTextUI::WarnAboutIffyMBRPart()
 
 /*********************************************************************
  *                                                                   *