summaryrefslogtreecommitdiff
path: root/tools/dosfstools/patches/0004-Make-all-char-that-may-take-literals-const.patch
blob: be553c8790621898c35dad98637c0029c53ea722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From 16e97e9741a02f6c2c29b3da45b62ac798d76403 Mon Sep 17 00:00:00 2001
From: Andreas Bombe <aeb@debian.org>
Date: Wed, 28 Jan 2015 15:07:18 +0100
Subject: [PATCH 04/14] Make all char* that may take literals const

Every char* variable or function argument that may be given a literal
string is now made const. Additionally add -Wwrite-strings to CFLAGS to
enable a warning where const would be missing.

Signed-off-by: Andreas Bombe <aeb@debian.org>
---
 Makefile       | 2 +-
 src/boot.c     | 4 ++--
 src/check.c    | 2 +-
 src/common.c   | 6 +++---
 src/common.h   | 6 +++---
 src/mkfs.fat.c | 8 +++++---
 6 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index 81256ef..3cbdb76 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ MANDIR = $(PREFIX)/share/man
 #OPTFLAGS = -O2 -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
 OPTFLAGS = -O2 -fomit-frame-pointer -D_GNU_SOURCE $(shell getconf LFS_CFLAGS)
 #WARNFLAGS = -Wall -pedantic -std=c99
-WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes
+WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
 DEBUGFLAGS = -g
 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS)
 
diff --git a/src/boot.c b/src/boot.c
index 5b3825c..be7bfb7 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -46,7 +46,7 @@
 
 static struct {
     __u8 media;
-    char *descr;
+    const char *descr;
 } mediabytes[] = {
     {
     0xf0, "5.25\" or 3.5\" HD floppy"}, {
@@ -64,7 +64,7 @@ static struct {
 #define GET_UNALIGNED_W(f)			\
     ( (__u16)f[0] | ((__u16)f[1]<<8) )
 
-static char *get_media_descr(unsigned char media)
+static const char *get_media_descr(unsigned char media)
 {
     int i;
 
diff --git a/src/check.c b/src/check.c
index daa6d69..488f715 100644
--- a/src/check.c
+++ b/src/check.c
@@ -464,7 +464,7 @@ static void rename_file(DOS_FILE * file)
 
 static int handle_dot(DOS_FS * fs, DOS_FILE * file, int dots)
 {
-    char *name;
+    const char *name;
 
     name =
 	strncmp((const char *)file->dir_ent.name, MSDOS_DOT,
diff --git a/src/common.c b/src/common.c
index af222a2..9d11193 100644
--- a/src/common.c
+++ b/src/common.c
@@ -37,7 +37,7 @@ typedef struct _link {
     struct _link *next;
 } LINK;
 
-void die(char *msg, ...)
+void die(const char *msg, ...)
 {
     va_list args;
 
@@ -48,7 +48,7 @@ void die(char *msg, ...)
     exit(1);
 }
 
-void pdie(char *msg, ...)
+void pdie(const char *msg, ...)
 {
     va_list args;
 
@@ -96,7 +96,7 @@ int min(int a, int b)
     return a < b ? a : b;
 }
 
-char get_key(char *valid, char *prompt)
+char get_key(const char *valid, const char *prompt)
 {
     int ch, okay;
 
diff --git a/src/common.h b/src/common.h
index 8508602..b127f63 100644
--- a/src/common.h
+++ b/src/common.h
@@ -25,11 +25,11 @@
 #ifndef _COMMON_H
 #define _COMMON_H
 
-void die(char *msg, ...) __attribute((noreturn));
+void die(const char *msg, ...) __attribute((noreturn));
 
 /* Displays a prinf-style message and terminates the program. */
 
-void pdie(char *msg, ...) __attribute((noreturn));
+void pdie(const char *msg, ...) __attribute((noreturn));
 
 /* Like die, but appends an error message according to the state of errno. */
 
@@ -50,7 +50,7 @@ int min(int a, int b);
 
 /* Returns the smaller integer value of a and b. */
 
-char get_key(char *valid, char *prompt);
+char get_key(const char *valid, const char *prompt);
 
 /* Displays PROMPT and waits for user input. Only characters in VALID are
    accepted. Terminates the program on EOF. Returns the character. */
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
index 1f702ad..a3dff54 100644
--- a/src/mkfs.fat.c
+++ b/src/mkfs.fat.c
@@ -250,7 +250,7 @@ char dummy_boot_code[BOOTCODE_SIZE] = "\x0e"	/* push cs */
 
 /* Global variables - the root of all evil :-) - see these and weep! */
 
-static char *program_name = "mkfs.fat";	/* Name of the program */
+static const char *program_name = "mkfs.fat";	/* Name of the program */
 static char *device_name = NULL;	/* Name of the device on which to create the filesystem */
 static int atari_format = 0;	/* Use Atari variation of MS-DOS FS format */
 static int check = FALSE;	/* Default to no readablity checking */
@@ -1412,6 +1412,7 @@ int main(int argc, char **argv)
     int create = 0;
     uint64_t cblocks = 0;
     int min_sector_size;
+    int bad_block_count = 0;
 
     if (argc && *argv) {	/* What's the program name? */
 	char *p;
@@ -1653,16 +1654,17 @@ int main(int argc, char **argv)
 	    fprintf(stderr, "Warning: block count mismatch: ");
 	    fprintf(stderr, "found %llu but assuming %llu.\n", (unsigned long long)cblocks, (unsigned long long)blocks);
 	}
+	if (*tmp)
+	    bad_block_count = 1;
     } else if (optind == argc - 1) {	/*  Or use value found */
 	if (create)
 	    die("Need intended size with -C.");
 	blocks = cblocks;
-	tmp = "";
     } else {
 	fprintf(stderr, "No device specified!\n");
 	usage();
     }
-    if (*tmp) {
+    if (bad_block_count) {
 	printf("Bad block count : %s\n", argv[optind + 1]);
 	usage();
     }
-- 
1.9.1