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 /basicmbr.cc | |
parent | 8dab6f22ee54e63d98cf303d16702794d091bcbb (diff) | |
download | sgdisk-9ae60195b9d24c01f535ade5b7bcf0e63c0600be.tar.gz |
Added explicit copy constructors and made other tweaks to avoid
compiler complaints.
Diffstat (limited to 'basicmbr.cc')
-rw-r--r-- | basicmbr.cc | 76 |
1 files changed, 54 insertions, 22 deletions
diff --git a/basicmbr.cc b/basicmbr.cc index 8fbffd1..dd48706 100644 --- a/basicmbr.cc +++ b/basicmbr.cc @@ -43,6 +43,36 @@ BasicMBRData::BasicMBRData(void) { EmptyMBR(); } // BasicMBRData default constructor +BasicMBRData::BasicMBRData(const BasicMBRData & orig) { + int i; + + if (&orig != this) { + memcpy(code, orig.code, 440); + diskSignature = orig.diskSignature; + nulls = orig.nulls; + MBRSignature = orig.MBRSignature; + blockSize = orig.blockSize; + diskSize = orig.diskSize; + numHeads = orig.numHeads; + numSecspTrack = orig.numSecspTrack; + canDeleteMyDisk = orig.canDeleteMyDisk; + device = orig.device; + state = orig.state; + + myDisk = new DiskIO; + if (myDisk == NULL) { + cerr << "Unable to allocate memory in BasicMBRData copy constructor! Terminating!\n"; + exit(1); + } // if + if (orig.myDisk != NULL) + myDisk->OpenForRead(orig.myDisk->GetName()); + + for (i = 0; i < MAX_MBR_PARTS; i++) { + partitions[i] = orig.partitions[i]; + } // for + } // if +} // BasicMBRData copy constructor + BasicMBRData::BasicMBRData(string filename) { blockSize = SECTOR_SIZE; diskSize = 0; @@ -73,29 +103,31 @@ BasicMBRData::~BasicMBRData(void) { BasicMBRData & BasicMBRData::operator=(const BasicMBRData & orig) { int i; - memcpy(code, orig.code, 440); - diskSignature = orig.diskSignature; - nulls = orig.nulls; - MBRSignature = orig.MBRSignature; - blockSize = orig.blockSize; - diskSize = orig.diskSize; - numHeads = orig.numHeads; - numSecspTrack = orig.numSecspTrack; - canDeleteMyDisk = orig.canDeleteMyDisk; - device = orig.device; - state = orig.state; - - myDisk = new DiskIO; - if (myDisk == NULL) { - cerr << "Unable to allocate memory in BasicMBRData::operator=()! Terminating!\n"; - exit(1); - } // if - if (orig.myDisk != NULL) - myDisk->OpenForRead(orig.myDisk->GetName()); + if (&orig != this) { + memcpy(code, orig.code, 440); + diskSignature = orig.diskSignature; + nulls = orig.nulls; + MBRSignature = orig.MBRSignature; + blockSize = orig.blockSize; + diskSize = orig.diskSize; + numHeads = orig.numHeads; + numSecspTrack = orig.numSecspTrack; + canDeleteMyDisk = orig.canDeleteMyDisk; + device = orig.device; + state = orig.state; - for (i = 0; i < MAX_MBR_PARTS; i++) { - partitions[i] = orig.partitions[i]; - } // for + myDisk = new DiskIO; + if (myDisk == NULL) { + cerr << "Unable to allocate memory in BasicMBRData::operator=()! Terminating!\n"; + exit(1); + } // if + if (orig.myDisk != NULL) + myDisk->OpenForRead(orig.myDisk->GetName()); + + for (i = 0; i < MAX_MBR_PARTS; i++) { + partitions[i] = orig.partitions[i]; + } // for + } // if return *this; } // BasicMBRData::operator=() |