Blame SOURCES/0062-Add-index-constant-definitions-instead-of-open-coded.patch

75bbb8
From d1586b86da52810014bd95e46fd5c86a458fca3e Mon Sep 17 00:00:00 2001
75bbb8
From: Robert Marshall <rmarshall@redhat.com>
75bbb8
Date: Tue, 13 Dec 2016 14:36:31 -0500
75bbb8
Subject: [PATCH 62/69] Add index constant definitions instead of open-coded
75bbb8
 values.
75bbb8
75bbb8
Added numeric constants NO_DEFAULT_ENTRY and FIRST_ENTRY_INDEX. This
75bbb8
clarifies the intent of various assignment operations throughout the
75bbb8
source file.
75bbb8
75bbb8
Related: rhbz#1285601
75bbb8
---
75bbb8
 grubby.c | 44 ++++++++++++++++++++++++--------------------
75bbb8
 1 file changed, 24 insertions(+), 20 deletions(-)
75bbb8
75bbb8
diff --git a/grubby.c b/grubby.c
75bbb8
index 344f1da..bece23a 100644
75bbb8
--- a/grubby.c
75bbb8
+++ b/grubby.c
75bbb8
@@ -130,6 +130,10 @@ struct singleEntry {
75bbb8
 #define NEED_END     (1 << 5)
75bbb8
 
75bbb8
 #define MAIN_DEFAULT	    (1 << 0)
75bbb8
+#define FIRST_ENTRY_INDEX    0	/* boot entry index value begin and increment
75bbb8
+				   from this initial value */
75bbb8
+#define NO_DEFAULT_ENTRY    -1	/* indicates that no specific default boot
75bbb8
+				   entry was set or currently exists */
75bbb8
 #define DEFAULT_SAVED       -2
75bbb8
 #define DEFAULT_SAVED_GRUB2 -3
75bbb8
 
75bbb8
@@ -1712,7 +1716,7 @@ static struct grubConfig *readConfig(const char *inName,
75bbb8
 						*end == ' ' || *end == '\t'))
75bbb8
 					end++;
75bbb8
 				if (*end)
75bbb8
-					cfg->defaultImage = -1;
75bbb8
+					cfg->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 			} else if (defaultLine->numElements == 3) {
75bbb8
 				char *value = defaultLine->elements[2].item;
75bbb8
 				while (*value && (*value == '"' ||
75bbb8
@@ -1725,7 +1729,7 @@ static struct grubConfig *readConfig(const char *inName,
75bbb8
 						*end == ' ' || *end == '\t'))
75bbb8
 					end++;
75bbb8
 				if (*end)
75bbb8
-					cfg->defaultImage = -1;
75bbb8
+					cfg->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 			}
75bbb8
 		} else if (cfi->defaultSupportSaved &&
75bbb8
 			   !strncmp(defaultLine->elements[1].item, "saved",
75bbb8
@@ -1735,7 +1739,7 @@ static struct grubConfig *readConfig(const char *inName,
75bbb8
 			cfg->defaultImage =
75bbb8
 			    strtol(defaultLine->elements[1].item, &end, 10);
75bbb8
 			if (*end)
75bbb8
-				cfg->defaultImage = -1;
75bbb8
+				cfg->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 		} else if (defaultLine->numElements >= 2) {
75bbb8
 			int i = 0;
75bbb8
 			while ((entry = findEntryByIndex(cfg, i))) {
75bbb8
@@ -1763,7 +1767,7 @@ static struct grubConfig *readConfig(const char *inName,
75bbb8
 			if (entry) {
75bbb8
 				cfg->defaultImage = i;
75bbb8
 			} else {
75bbb8
-				cfg->defaultImage = -1;
75bbb8
+				cfg->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 			}
75bbb8
 		}
75bbb8
 	} else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) {
75bbb8
@@ -1780,7 +1784,7 @@ static struct grubConfig *readConfig(const char *inName,
75bbb8
 				cfg->defaultImage = index;
75bbb8
 		}
75bbb8
 	} else {
75bbb8
-		cfg->defaultImage = 0;
75bbb8
+		cfg->defaultImage = FIRST_ENTRY_INDEX;
75bbb8
 	}
75bbb8
 
75bbb8
 	return cfg;
75bbb8
@@ -1800,7 +1804,7 @@ static void writeDefault(FILE * out, char *indent,
75bbb8
 		fprintf(out, "%sdefault%ssaved\n", indent, separator);
75bbb8
 	else if (cfg->cfi->defaultIsSaved) {
75bbb8
 		fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);
75bbb8
-		if (cfg->defaultImage >= 0 && cfg->cfi->setEnv) {
75bbb8
+		if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) {
75bbb8
 			char *title;
75bbb8
 			entry = findEntryByIndex(cfg, cfg->defaultImage);
75bbb8
 			line = getLineByType(LT_MENUENTRY, entry->lines);
75bbb8
@@ -1813,7 +1817,7 @@ static void writeDefault(FILE * out, char *indent,
75bbb8
 							 "saved_entry", title);
75bbb8
 			}
75bbb8
 		}
75bbb8
-	} else if (cfg->defaultImage > -1) {
75bbb8
+	} else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) {
75bbb8
 		if (cfg->cfi->defaultIsIndex) {
75bbb8
 			if (cfg->cfi->defaultIsVariable) {
75bbb8
 				fprintf(out, "%sset default=\"%d\"\n", indent,
75bbb8
@@ -2515,7 +2519,7 @@ struct singleEntry *findTemplate(struct grubConfig *cfg, const char *prefix,
75bbb8
 				}
75bbb8
 			}
75bbb8
 		}
75bbb8
-	} else if (cfg->defaultImage > -1) {
75bbb8
+	} else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) {
75bbb8
 		entry = findEntryByIndex(cfg, cfg->defaultImage);
75bbb8
 		if (entry && suitableImage(entry, prefix, skipRemoved, flags)) {
75bbb8
 			if (indexPtr)
75bbb8
@@ -2597,20 +2601,20 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath,
75bbb8
 	int i, j;
75bbb8
 
75bbb8
 	if (newBootEntryIsDefault) {
75bbb8
-		config->defaultImage = 0;
75bbb8
+		config->defaultImage = FIRST_ENTRY_INDEX;
75bbb8
 		return;
75bbb8
 	} else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) {
75bbb8
 		if (findEntryByIndex(config, newDefaultBootEntryIndex))
75bbb8
 			config->defaultImage = newDefaultBootEntryIndex;
75bbb8
 		else
75bbb8
-			config->defaultImage = -1;
75bbb8
+			config->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 		return;
75bbb8
 	} else if (defaultKernelPath) {
75bbb8
 		i = 0;
75bbb8
 		if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {
75bbb8
 			config->defaultImage = i;
75bbb8
 		} else {
75bbb8
-			config->defaultImage = -1;
75bbb8
+			config->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 			return;
75bbb8
 		}
75bbb8
 	}
75bbb8
@@ -2622,7 +2626,7 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath,
75bbb8
 		/* default is set to saved, we don't want to change it */
75bbb8
 		return;
75bbb8
 
75bbb8
-	if (config->defaultImage > -1)
75bbb8
+	if (config->defaultImage >= FIRST_ENTRY_INDEX)
75bbb8
 		entry = findEntryByIndex(config, config->defaultImage);
75bbb8
 	else
75bbb8
 		entry = NULL;
75bbb8
@@ -2639,7 +2643,7 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath,
75bbb8
 				config->defaultImage--;
75bbb8
 		}
75bbb8
 	} else if (isUserSpecifiedKernelPath) {
75bbb8
-		config->defaultImage = 0;
75bbb8
+		config->defaultImage = FIRST_ENTRY_INDEX;
75bbb8
 	} else {
75bbb8
 		/* Either we just erased the default (or the default line was bad
75bbb8
 		 * to begin with) and didn't put a new one in. We'll use the first
75bbb8
@@ -2648,7 +2652,7 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath,
75bbb8
 		    findTemplate(config, prefix, &config->defaultImage, 1,
75bbb8
 				 flags);
75bbb8
 		if (!newDefault)
75bbb8
-			config->defaultImage = -1;
75bbb8
+			config->defaultImage = NO_DEFAULT_ENTRY;
75bbb8
 	}
75bbb8
 }
75bbb8
 
75bbb8
@@ -5210,11 +5214,11 @@ int main(int argc, const char **argv)
75bbb8
 		struct singleEntry *entry;
75bbb8
 		char *rootspec;
75bbb8
 
75bbb8
-		if (config->defaultImage == -1)
75bbb8
+		if (config->defaultImage == NO_DEFAULT_ENTRY)
75bbb8
 			return 0;
75bbb8
 		if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
75bbb8
 		    cfi->defaultIsSaved)
75bbb8
-			config->defaultImage = 0;
75bbb8
+			config->defaultImage = FIRST_ENTRY_INDEX;
75bbb8
 		entry = findEntryByIndex(config, config->defaultImage);
75bbb8
 		if (!entry)
75bbb8
 			return 0;
75bbb8
@@ -5237,11 +5241,11 @@ int main(int argc, const char **argv)
75bbb8
 		struct singleLine *line;
75bbb8
 		struct singleEntry *entry;
75bbb8
 
75bbb8
-		if (config->defaultImage == -1)
75bbb8
+		if (config->defaultImage == NO_DEFAULT_ENTRY)
75bbb8
 			return 0;
75bbb8
 		if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
75bbb8
 		    cfi->defaultIsSaved)
75bbb8
-			config->defaultImage = 0;
75bbb8
+			config->defaultImage = FIRST_ENTRY_INDEX;
75bbb8
 		entry = findEntryByIndex(config, config->defaultImage);
75bbb8
 		if (!entry)
75bbb8
 			return 0;
75bbb8
@@ -5271,11 +5275,11 @@ int main(int argc, const char **argv)
75bbb8
 		return 0;
75bbb8
 
75bbb8
 	} else if (displayDefaultIndex) {
75bbb8
-		if (config->defaultImage == -1)
75bbb8
+		if (config->defaultImage == NO_DEFAULT_ENTRY)
75bbb8
 			return 0;
75bbb8
 		if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
75bbb8
 		    cfi->defaultIsSaved)
75bbb8
-			config->defaultImage = 0;
75bbb8
+			config->defaultImage = FIRST_ENTRY_INDEX;
75bbb8
 		printf("%i\n", config->defaultImage);
75bbb8
 		return 0;
75bbb8
 
75bbb8
-- 
75bbb8
2.9.3
75bbb8