diff options
author | Rod Smith <rodsmith@rodsbooks.com> | 2018-07-05 16:50:13 -0400 |
---|---|---|
committer | Rod Smith <rodsmith@rodsbooks.com> | 2018-07-05 16:50:13 -0400 |
commit | 9ae60195b9d24c01f535ade5b7bcf0e63c0600be (patch) | |
tree | 3f7c35f56cb9222be3081c57b3f7d61af3390483 /gpt.cc | |
parent | 8dab6f22ee54e63d98cf303d16702794d091bcbb (diff) | |
download | sgdisk-9ae60195b9d24c01f535ade5b7bcf0e63c0600be.tar.gz |
Added explicit copy constructors and made other tweaks to avoid
compiler complaints.
Diffstat (limited to 'gpt.cc')
-rw-r--r-- | gpt.cc | 103 |
1 files changed, 72 insertions, 31 deletions
@@ -86,6 +86,45 @@ GPTData::GPTData(void) { chksum_crc32gentab(); } // GPTData default constructor +GPTData::GPTData(const GPTData & orig) { + uint32_t i; + + if (&orig != this) { + mainHeader = orig.mainHeader; + numParts = orig.numParts; + secondHeader = orig.secondHeader; + protectiveMBR = orig.protectiveMBR; + device = orig.device; + blockSize = orig.blockSize; + physBlockSize = orig.physBlockSize; + diskSize = orig.diskSize; + state = orig.state; + justLooking = orig.justLooking; + mainCrcOk = orig.mainCrcOk; + secondCrcOk = orig.secondCrcOk; + mainPartsCrcOk = orig.mainPartsCrcOk; + secondPartsCrcOk = orig.secondPartsCrcOk; + apmFound = orig.apmFound; + bsdFound = orig.bsdFound; + sectorAlignment = orig.sectorAlignment; + beQuiet = orig.beQuiet; + whichWasUsed = orig.whichWasUsed; + + myDisk.OpenForRead(orig.myDisk.GetName()); + + delete[] partitions; + partitions = new GPTPart [numParts]; + if (partitions == NULL) { + cerr << "Error! Could not allocate memory for partitions in GPTData::operator=()!\n" + << "Terminating!\n"; + exit(1); + } // if + for (i = 0; i < numParts; i++) { + partitions[i] = orig.partitions[i]; + } // for + } // if +} // GPTData copy constructor + // The following constructor loads GPT data from a device file GPTData::GPTData(string filename) { blockSize = SECTOR_SIZE; // set a default @@ -120,38 +159,40 @@ GPTData::~GPTData(void) { GPTData & GPTData::operator=(const GPTData & orig) { uint32_t i; - mainHeader = orig.mainHeader; - numParts = orig.numParts; - secondHeader = orig.secondHeader; - protectiveMBR = orig.protectiveMBR; - device = orig.device; - blockSize = orig.blockSize; - physBlockSize = orig.physBlockSize; - diskSize = orig.diskSize; - state = orig.state; - justLooking = orig.justLooking; - mainCrcOk = orig.mainCrcOk; - secondCrcOk = orig.secondCrcOk; - mainPartsCrcOk = orig.mainPartsCrcOk; - secondPartsCrcOk = orig.secondPartsCrcOk; - apmFound = orig.apmFound; - bsdFound = orig.bsdFound; - sectorAlignment = orig.sectorAlignment; - beQuiet = orig.beQuiet; - whichWasUsed = orig.whichWasUsed; - - myDisk.OpenForRead(orig.myDisk.GetName()); - - delete[] partitions; - partitions = new GPTPart [numParts]; - if (partitions == NULL) { - cerr << "Error! Could not allocate memory for partitions in GPTData::operator=()!\n" - << "Terminating!\n"; - exit(1); + if (&orig != this) { + mainHeader = orig.mainHeader; + numParts = orig.numParts; + secondHeader = orig.secondHeader; + protectiveMBR = orig.protectiveMBR; + device = orig.device; + blockSize = orig.blockSize; + physBlockSize = orig.physBlockSize; + diskSize = orig.diskSize; + state = orig.state; + justLooking = orig.justLooking; + mainCrcOk = orig.mainCrcOk; + secondCrcOk = orig.secondCrcOk; + mainPartsCrcOk = orig.mainPartsCrcOk; + secondPartsCrcOk = orig.secondPartsCrcOk; + apmFound = orig.apmFound; + bsdFound = orig.bsdFound; + sectorAlignment = orig.sectorAlignment; + beQuiet = orig.beQuiet; + whichWasUsed = orig.whichWasUsed; + + myDisk.OpenForRead(orig.myDisk.GetName()); + + delete[] partitions; + partitions = new GPTPart [numParts]; + if (partitions == NULL) { + cerr << "Error! Could not allocate memory for partitions in GPTData::operator=()!\n" + << "Terminating!\n"; + exit(1); + } // if + for (i = 0; i < numParts; i++) { + partitions[i] = orig.partitions[i]; + } // for } // if - for (i = 0; i < numParts; i++) { - partitions[i] = orig.partitions[i]; - } // for return *this; } // GPTData::operator=() |