openwrt/tools/dosfstools/patches/0004-Make-all-char-that-may-take-literals-const.patch

170 lines
5.0 KiB
Diff
Raw Normal View History

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