{"thread":{"id":"248","subject":"[PATCH] Constify","startedAt":"2005-04-22T18:08:02Z","lastAt":"2005-05-17T21:27:42Z","messageCount":2,"participants":["Morten Welinder","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"1304","messageId":"118833cc050422110872a6f4a5@mail.gmail.com","threadId":"248","inReplyTo":null,"subject":"[PATCH] Constify","fromName":"Morten Welinder","fromEmail":"mwelinder@gmail.com","sentAt":"2005-04-22T18:08:02Z","receivedAt":"2005-04-22T18:08:02Z","isPatch":true,"sender":{"key":"mwelinder@gmail.com","avatar":null},"body":"Hi!\n\nThis patch makes strings type \"const char *\" and keeps people honest.\n[Here's to hoping that nothing in this email setup mangles whitespace...]\n\nSigned-off-by: Morten Welinder (mwelinder@gmail.com)\n\n\nIndex: Makefile\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/Makefile  (mode:100644\nsha1:2d7e4cf0464c45b7c5b169bff7e5c4e7768c13a1)\n+++ uncommitted/Makefile  (mode:100664)\n@@ -12,7 +12,7 @@\n # BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely randomly\n # break unless your underlying filesystem supports those sub-second times\n # (my ext3 doesn't).\n-CFLAGS=-g -O2 -Wall\n+CFLAGS=-g -O2 -Wall -Wwrite-strings\n \n # Should be changed to /usr/local\n prefix=$(HOME)\nIndex: commit-tree.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/commit-tree.c \n(mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1)\n+++ uncommitted/commit-tree.c  (mode:100664)\n@@ -62,7 +62,7 @@\n \treturn i;\n }\n \n-static void finish_buffer(char *tag, char **bufp, unsigned int *sizep)\n+static void finish_buffer(const char *tag, char **bufp, unsigned int *sizep)\n {\n \tint taglen;\n \tint offset;\n@@ -273,7 +273,7 @@\n  */\n #define MAXPARENT (16)\n \n-static char *commit_tree_usage = \"commit-tree <sha1> [-p <sha1>]* < changelog\";\n+static const char *commit_tree_usage = \"commit-tree <sha1> [-p\n<sha1>]* < changelog\";\n \n int main(int argc, char **argv)\n {\nIndex: diff-cache.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/diff-cache.c \n(mode:100644 sha1:5e1d1a6e6d83291964dca82e6969e576f6a839ec)\n+++ uncommitted/diff-cache.c  (mode:100664)\n@@ -215,7 +215,7 @@\n \treturn 0;\n }\n \n-static char *diff_cache_usage = \"diff-cache [-r] [-z] [--cached] <tree sha1>\";\n+static const char *diff_cache_usage = \"diff-cache [-r] [-z]\n[--cached] <tree sha1>\";\n \n int main(int argc, char **argv)\n {\nIndex: diff-tree.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/diff-tree.c  (mode:100644\nsha1:0f370927dd2496a420af53d137676b6c3c445f75)\n+++ uncommitted/diff-tree.c  (mode:100664)\n@@ -178,7 +178,7 @@\n \treturn retval;\n }\n \n-static char *diff_tree_usage = \"diff-tree [-r] [-z] <tree sha1> <tree sha1>\";\n+static const char *diff_tree_usage = \"diff-tree [-r] [-z] <tree sha1>\n<tree sha1>\";\n \n int main(int argc, char **argv)\n {\nIndex: fsck-cache.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/fsck-cache.c \n(mode:100644 sha1:96b8eb161107cd3219975d93a44874a5455b702e)\n+++ uncommitted/fsck-cache.c  (mode:100664)\n@@ -134,7 +134,7 @@\n int main(int argc, char **argv)\n {\n \tint i, heads;\n-\tchar *sha1_dir;\n+\tconst char *sha1_dir;\n \n \tsha1_dir = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;\n \tfor (i = 0; i < 256; i++) {\nIndex: init-db.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/init-db.c  (mode:100644\nsha1:dad06351ca35d0d2f68cd9e719c49805386f96fa)\n+++ uncommitted/init-db.c  (mode:100664)\n@@ -5,7 +5,7 @@\n  */\n #include \"cache.h\"\n \n-void safe_create_dir(char *dir)\n+void safe_create_dir(const char *dir)\n {\n \tif (mkdir(dir, 0755) < 0) {\n \t\tif (errno != EEXIST) {\n@@ -23,7 +23,8 @@\n  */\n int main(int argc, char **argv)\n {\n-\tchar *sha1_dir, *path;\n+\tconst char *sha1_dir;\n+\tchar *path;\n \tint len, i;\n \n \tsafe_create_dir(\".git\");\nIndex: read-tree.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/read-tree.c  (mode:100644\nsha1:7c938491ad358582c610edac4a36a03868f8631d)\n+++ uncommitted/read-tree.c  (mode:100664)\n@@ -221,7 +221,7 @@\n \t}\n }\n \n-static char *read_tree_usage = \"read-tree (<sha> | -m <sha1> [<sha2> <sha3>])\";\n+static const char *read_tree_usage = \"read-tree (<sha> | -m <sha1>\n[<sha2> <sha3>])\";\n \n int main(int argc, char **argv)\n {\nIndex: sha1_file.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/sha1_file.c  (mode:100644\nsha1:f356acc9e6ce705fdfb947a5f36bba66fd9cd797)\n+++ uncommitted/sha1_file.c  (mode:100664)\n@@ -61,7 +61,7 @@\n \tstatic char *name, *base;\n \n \tif (!base) {\n-\t\tchar *sha1_file_directory = getenv(DB_ENVIRONMENT) ? :\nDEFAULT_DB_ENVIRONMENT;\n+\t\tconst char *sha1_file_directory = getenv(DB_ENVIRONMENT) ? :\nDEFAULT_DB_ENVIRONMENT;\n \t\tint len = strlen(sha1_file_directory);\n \t\tbase = malloc(len + 60);\n \t\tmemcpy(base, sha1_file_directory, len);\nIndex: show-diff.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/show-diff.c  (mode:100644\nsha1:da364e26e28823f951a6be1b686a458575f28ea1)\n+++ uncommitted/show-diff.c  (mode:100664)\n@@ -5,10 +5,10 @@\n  */\n #include \"cache.h\"\n \n-static char *diff_cmd = \"diff -L 'a/%s' -L 'b/%s' \";\n-static char *diff_opts = \"-p -u\";\n-static char *diff_arg_forward  = \" - '%s'\";\n-static char *diff_arg_reverse  = \" '%s' -\";\n+static const char *diff_cmd = \"diff -L 'a/%s' -L 'b/%s' \";\n+static const char *diff_opts = \"-p -u\";\n+static const char *diff_arg_forward  = \" - '%s'\";\n+static const char *diff_arg_reverse  = \" '%s' -\";\n \n static void prepare_diff_cmd(void)\n {\n@@ -35,15 +35,16 @@\n  *  a b      ==> a b       ==> 'a b'\n  *  a'b      ==> a'\\''b    ==> 'a'\\''b'\n  */\n-static char *sq_expand(char *src)\n+static char *sq_expand(const char *src)\n {\n \tstatic char *buf = NULL;\n \tint cnt, c;\n \tchar *cp;\n+\tconst char *sp;\n \n \t/* count bytes needed to store the quoted string. */ \n-\tfor (cnt = 1, cp = src; *cp; cnt++, cp++)\n-\t\tif (*cp == '\\'')\n+\tfor (cnt = 1, sp = src; *sp; cnt++, sp++)\n+\t\tif (*sp == '\\'')\n \t\t\tcnt += 3;\n \n \tif (! (buf = malloc(cnt)))\n@@ -61,13 +62,13 @@\n \treturn buf;\n }\n \n-static void show_differences(char *name, char *label, void *old_contents,\n+static void show_differences(const char *name, char *label, void *old_contents,\n \t\t\t     unsigned long long old_size, int reverse)\n {\n \tFILE *f;\n \tchar *name_sq = sq_expand(name);\n \tchar *label_sq = (name != label) ? sq_expand(label) : name_sq;\n-\tchar *diff_arg = reverse ? diff_arg_reverse : diff_arg_forward;\n+\tconst char *diff_arg = reverse ? diff_arg_reverse : diff_arg_forward;\n \tint cmd_size = strlen(name_sq) + strlen(label_sq) * 2 +\n \t\tstrlen(diff_cmd) + strlen(diff_opts) + strlen(diff_arg);\n \tchar *cmd = malloc(cmd_size);\nIndex: update-cache.c\n===================================================================\n--- 9f6f9ee7ad29cafe4265eae5050ce712b00bfce0/update-cache.c \n(mode:100644 sha1:9ad4ae278703ee621b723afc65f3a51038e30f52)\n+++ uncommitted/update-cache.c  (mode:100664)\n@@ -25,9 +25,11 @@\n \tvoid *in;\n \tSHA_CTX c;\n \n-\tin = \"\";\n \tif (size)\n \t\tin = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\telse\n+\t\tin = (void *)\"\";\n+\n \tclose(fd);\n \tif (!out || (int)(long)in == -1)\n \t\treturn -1;\n"},{"id":"3474","messageId":"20050517212742.GM7136@pasky.ji.cz","threadId":"248","inReplyTo":"118833cc050422110872a6f4a5@mail.gmail.com","subject":"Re: [PATCH] Constify","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-17T21:27:42Z","receivedAt":"2005-05-17T21:27:42Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Fri, Apr 22, 2005 at 08:08:02PM CEST, I got a letter\nwhere Morten Welinder <mwelinder@gmail.com> told me that...\n> Hi!\n\nHello,\n\n> This patch makes strings type \"const char *\" and keeps people honest.\n> [Here's to hoping that nothing in this email setup mangles whitespace...]\n> \n> Signed-off-by: Morten Welinder (mwelinder@gmail.com)\n\nthanks. It was somewhat mangled, but the main problem was that it has\nrot for too long in my queue, so only quite small part of it survived\nuntil today. :-( I've not applied the CFLAGS+=-Wwrite-strings part yet,\nsince it would require some additional cleanups and such, so I'll let\nsomeone else deal with that. ;-)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"}]}