0004-Make-all-char-that-may-take-literals-const.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. From 16e97e9741a02f6c2c29b3da45b62ac798d76403 Mon Sep 17 00:00:00 2001
  2. From: Andreas Bombe <aeb@debian.org>
  3. Date: Wed, 28 Jan 2015 15:07:18 +0100
  4. Subject: [PATCH 04/14] Make all char* that may take literals const
  5. Every char* variable or function argument that may be given a literal
  6. string is now made const. Additionally add -Wwrite-strings to CFLAGS to
  7. enable a warning where const would be missing.
  8. Signed-off-by: Andreas Bombe <aeb@debian.org>
  9. ---
  10. Makefile | 2 +-
  11. src/boot.c | 4 ++--
  12. src/check.c | 2 +-
  13. src/common.c | 6 +++---
  14. src/common.h | 6 +++---
  15. src/mkfs.fat.c | 8 +++++---
  16. 6 files changed, 15 insertions(+), 13 deletions(-)
  17. diff --git a/Makefile b/Makefile
  18. index 81256ef..3cbdb76 100644
  19. --- a/Makefile
  20. +++ b/Makefile
  21. @@ -30,7 +30,7 @@ MANDIR = $(PREFIX)/share/man
  22. #OPTFLAGS = -O2 -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
  23. OPTFLAGS = -O2 -fomit-frame-pointer -D_GNU_SOURCE $(shell getconf LFS_CFLAGS)
  24. #WARNFLAGS = -Wall -pedantic -std=c99
  25. -WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes
  26. +WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
  27. DEBUGFLAGS = -g
  28. CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS)
  29. diff --git a/src/boot.c b/src/boot.c
  30. index 5b3825c..be7bfb7 100644
  31. --- a/src/boot.c
  32. +++ b/src/boot.c
  33. @@ -46,7 +46,7 @@
  34. static struct {
  35. __u8 media;
  36. - char *descr;
  37. + const char *descr;
  38. } mediabytes[] = {
  39. {
  40. 0xf0, "5.25\" or 3.5\" HD floppy"}, {
  41. @@ -64,7 +64,7 @@ static struct {
  42. #define GET_UNALIGNED_W(f) \
  43. ( (__u16)f[0] | ((__u16)f[1]<<8) )
  44. -static char *get_media_descr(unsigned char media)
  45. +static const char *get_media_descr(unsigned char media)
  46. {
  47. int i;
  48. diff --git a/src/check.c b/src/check.c
  49. index daa6d69..488f715 100644
  50. --- a/src/check.c
  51. +++ b/src/check.c
  52. @@ -464,7 +464,7 @@ static void rename_file(DOS_FILE * file)
  53. static int handle_dot(DOS_FS * fs, DOS_FILE * file, int dots)
  54. {
  55. - char *name;
  56. + const char *name;
  57. name =
  58. strncmp((const char *)file->dir_ent.name, MSDOS_DOT,
  59. diff --git a/src/common.c b/src/common.c
  60. index af222a2..9d11193 100644
  61. --- a/src/common.c
  62. +++ b/src/common.c
  63. @@ -37,7 +37,7 @@ typedef struct _link {
  64. struct _link *next;
  65. } LINK;
  66. -void die(char *msg, ...)
  67. +void die(const char *msg, ...)
  68. {
  69. va_list args;
  70. @@ -48,7 +48,7 @@ void die(char *msg, ...)
  71. exit(1);
  72. }
  73. -void pdie(char *msg, ...)
  74. +void pdie(const char *msg, ...)
  75. {
  76. va_list args;
  77. @@ -96,7 +96,7 @@ int min(int a, int b)
  78. return a < b ? a : b;
  79. }
  80. -char get_key(char *valid, char *prompt)
  81. +char get_key(const char *valid, const char *prompt)
  82. {
  83. int ch, okay;
  84. diff --git a/src/common.h b/src/common.h
  85. index 8508602..b127f63 100644
  86. --- a/src/common.h
  87. +++ b/src/common.h
  88. @@ -25,11 +25,11 @@
  89. #ifndef _COMMON_H
  90. #define _COMMON_H
  91. -void die(char *msg, ...) __attribute((noreturn));
  92. +void die(const char *msg, ...) __attribute((noreturn));
  93. /* Displays a prinf-style message and terminates the program. */
  94. -void pdie(char *msg, ...) __attribute((noreturn));
  95. +void pdie(const char *msg, ...) __attribute((noreturn));
  96. /* Like die, but appends an error message according to the state of errno. */
  97. @@ -50,7 +50,7 @@ int min(int a, int b);
  98. /* Returns the smaller integer value of a and b. */
  99. -char get_key(char *valid, char *prompt);
  100. +char get_key(const char *valid, const char *prompt);
  101. /* Displays PROMPT and waits for user input. Only characters in VALID are
  102. accepted. Terminates the program on EOF. Returns the character. */
  103. diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
  104. index 1f702ad..a3dff54 100644
  105. --- a/src/mkfs.fat.c
  106. +++ b/src/mkfs.fat.c
  107. @@ -250,7 +250,7 @@ char dummy_boot_code[BOOTCODE_SIZE] = "\x0e" /* push cs */
  108. /* Global variables - the root of all evil :-) - see these and weep! */
  109. -static char *program_name = "mkfs.fat"; /* Name of the program */
  110. +static const char *program_name = "mkfs.fat"; /* Name of the program */
  111. static char *device_name = NULL; /* Name of the device on which to create the filesystem */
  112. static int atari_format = 0; /* Use Atari variation of MS-DOS FS format */
  113. static int check = FALSE; /* Default to no readablity checking */
  114. @@ -1412,6 +1412,7 @@ int main(int argc, char **argv)
  115. int create = 0;
  116. uint64_t cblocks = 0;
  117. int min_sector_size;
  118. + int bad_block_count = 0;
  119. if (argc && *argv) { /* What's the program name? */
  120. char *p;
  121. @@ -1653,16 +1654,17 @@ int main(int argc, char **argv)
  122. fprintf(stderr, "Warning: block count mismatch: ");
  123. fprintf(stderr, "found %llu but assuming %llu.\n", (unsigned long long)cblocks, (unsigned long long)blocks);
  124. }
  125. + if (*tmp)
  126. + bad_block_count = 1;
  127. } else if (optind == argc - 1) { /* Or use value found */
  128. if (create)
  129. die("Need intended size with -C.");
  130. blocks = cblocks;
  131. - tmp = "";
  132. } else {
  133. fprintf(stderr, "No device specified!\n");
  134. usage();
  135. }
  136. - if (*tmp) {
  137. + if (bad_block_count) {
  138. printf("Bad block count : %s\n", argv[optind + 1]);
  139. usage();
  140. }
  141. --
  142. 1.9.1