summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRod Smith <rodsmith@rodsbooks.com>2018-07-05 16:50:13 -0400
committerRod Smith <rodsmith@rodsbooks.com>2018-07-05 16:50:13 -0400
commit9ae60195b9d24c01f535ade5b7bcf0e63c0600be (patch)
tree3f7c35f56cb9222be3081c57b3f7d61af3390483
parent8dab6f22ee54e63d98cf303d16702794d091bcbb (diff)
downloadsgdisk-9ae60195b9d24c01f535ade5b7bcf0e63c0600be.tar.gz
Added explicit copy constructors and made other tweaks to avoid
compiler complaints.
-rw-r--r--Makefile.mac3
-rw-r--r--NEWS11
-rw-r--r--basicmbr.cc76
-rw-r--r--basicmbr.h1
-rw-r--r--gpt.cc103
-rw-r--r--gpt.h1
-rw-r--r--gptcurses.cc3
-rw-r--r--gptpart.cc9
-rw-r--r--gptpart.h1
9 files changed, 153 insertions, 55 deletions
diff --git a/Makefile.mac b/Makefile.mac
index 6c0fa25..27f95b7 100644
--- a/Makefile.mac
+++ b/Makefile.mac
@@ -1,6 +1,7 @@
CC=gcc
CXX=clang++
FATBINFLAGS=-arch x86_64 -arch i386 -mmacosx-version-min=10.4
+THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.4
CFLAGS=$(FATBINFLAGS) -O2 -D_FILE_OFFSET_BITS=64 -g
#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/opt/local/include -I/usr/local/include -I/opt/local/include -g
CXXFLAGS=$(FATBINFLAGS) -O2 -Wall -D_FILE_OFFSET_BITS=64 -I/opt/local/include -I /usr/local/include -I/opt/local/include -g
@@ -24,7 +25,7 @@ cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o
sgdisk: $(LIB_OBJS) gptcl.o sgdisk.o
# $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o /opt/local/lib/libiconv.a /opt/local/lib/libintl.a /opt/local/lib/libpopt.a $(FATBINFLAGS) -o sgdisk
- $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o -L/opt/local/lib -lpopt $(FATBINFLAGS) -o sgdisk
+ $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o -L/usr/local/lib -lpopt $(THINBINFLAGS) -o sgdisk
# $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o -L/sw/lib -licucore -lpopt -o sgdisk
fixparts: $(MBR_LIB_OBJS) fixparts.o
diff --git a/NEWS b/NEWS
index 9972074..2a82658 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,17 @@
1.0.4 (7/5/2018):
-----------------
+- Added some explicit copy constructors and made some other tweaks to avoid
+ compiler warnings.
+
+- The macOS binary for sgdisk is now a pure 64-bit build; I'm no longer
+ supporting 32-bit builds of sgdisk. The gdisk and cgdisk binaries remain
+ "fat" 32-/64-bit builds. The reason for dropping the 32-bit support from
+ sgdisk is that I've re-built my macOS development system, and I had
+ trouble building a "fat" binary with the fresh install of the popt
+ libraries upon which sgdisk relies. 32-bit support for the other binaries
+ is now officially deprecated, too.
+
- Added search feature to partition type list functions ("L" on main menu of
gdisk and "L" when entered in response to the "Hex code or GUID" prompt in
gdisk and sgdisk). This feature filters the partition type list to those
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=()
diff --git a/basicmbr.h b/basicmbr.h
index 21f962e..504e039 100644
--- a/basicmbr.h
+++ b/basicmbr.h
@@ -63,6 +63,7 @@ protected:
public:
BasicMBRData(void);
BasicMBRData(string deviceFilename);
+ BasicMBRData(const BasicMBRData &);
~BasicMBRData(void);
BasicMBRData & operator=(const BasicMBRData & orig);
diff --git a/gpt.cc b/gpt.cc
index c054460..fe8e956 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -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=()
diff --git a/gpt.h b/gpt.h
index f4bf470..a5be961 100644
--- a/gpt.h
+++ b/gpt.h
@@ -92,6 +92,7 @@ protected:
public:
// Basic necessary functions....
GPTData(void);
+ GPTData(const GPTData &);
GPTData(string deviceFilename);
virtual ~GPTData(void);
GPTData & operator=(const GPTData & orig);
diff --git a/gptcurses.cc b/gptcurses.cc
index a9f466c..3e9b240 100644
--- a/gptcurses.cc
+++ b/gptcurses.cc
@@ -394,6 +394,7 @@ void GPTDataCurses::ChangeType(int partNum) {
// Sets the partition alignment value
void GPTDataCurses::SetAlignment(void) {
int alignment;
+ char conversion_specifier[] = "%d";
move(LINES - 4, 0);
clrtobot();
@@ -402,7 +403,7 @@ void GPTDataCurses::SetAlignment(void) {
move(LINES - 3, 0);
printw("Type new alignment value, in sectors: ");
echo();
- scanw("%d", &alignment);
+ scanw(conversion_specifier, &alignment);
noecho();
} while ((alignment == 0) || (alignment > MAX_ALIGNMENT));
GPTData::SetAlignment(alignment);
diff --git a/gptpart.cc b/gptpart.cc
index 40a90a3..666263b 100644
--- a/gptpart.cc
+++ b/gptpart.cc
@@ -38,6 +38,15 @@ GPTPart::GPTPart(void) {
memset(name, 0, NAME_SIZE * sizeof(name[0]) );
} // Default constructor
+GPTPart::GPTPart(const GPTPart & orig) {
+ partitionType = orig.partitionType;
+ uniqueGUID = orig.uniqueGUID;
+ firstLBA = orig.firstLBA;
+ lastLBA = orig.lastLBA;
+ attributes = orig.attributes;
+ memcpy(name, orig.name, NAME_SIZE * sizeof( name[ 0 ] ) );
+} // Copy constructor
+
GPTPart::~GPTPart(void) {
} // destructor
diff --git a/gptpart.h b/gptpart.h
index 657b3f9..fac514e 100644
--- a/gptpart.h
+++ b/gptpart.h
@@ -53,6 +53,7 @@ class GPTPart {
uint16_t name[NAME_SIZE];
public:
GPTPart(void);
+ GPTPart(const GPTPart &);
~GPTPart(void);
// Simple data retrieval: