From 70f439d9a9957ff90138b4ce4c31f1dfe922852c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Tue, 7 Apr 2020 21:46:47 +0200
Subject: [PATCH] Enforce const correctness on strings

(cherry picked from commit 9801f46ece0ca2525f02d71464efc42296dddcb5)
---
 src/browser.c    |  4 ++--
 src/dir_common.c |  2 +-
 src/help.c       |  2 +-
 src/shell.c      |  4 ++--
 src/util.c       | 10 +++++-----
 src/util.h       |  8 ++++----
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index 6a4ce1a..61c38a4 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -32,7 +32,7 @@
 
 
 static int graph = 1, show_as = 0, info_show = 0, info_page = 0, info_start = 0, show_items = 0, show_mtime = 0;
-static char *message = NULL;
+static const char *message = NULL;
 
 
 
@@ -256,7 +256,7 @@ static void browse_draw_item(struct dir *n, int row) {
 
 void browse_draw() {
   struct dir *t;
-  char *tmp;
+  const char *tmp;
   int selected = 0, i;
 
   erase();
diff --git a/src/dir_common.c b/src/dir_common.c
index bee9bf1..a2fab2a 100644
--- a/src/dir_common.c
+++ b/src/dir_common.c
@@ -181,7 +181,7 @@ static void draw_error(char *cur, char *msg) {
 
 void dir_draw() {
   float f;
-  char *unit;
+  const char *unit;
 
   switch(dir_ui) {
   case 0:
diff --git a/src/help.c b/src/help.c
index b41d7bd..c1b2f63 100644
--- a/src/help.c
+++ b/src/help.c
@@ -33,7 +33,7 @@ int page, start;
 
 
 #define KEYS 19
-char *keys[KEYS*2] = {
+const char *keys[KEYS*2] = {
 /*|----key----|  |----------------description----------------|*/
         "up, k", "Move cursor up",
       "down, j", "Move cursor down",
diff --git a/src/shell.c b/src/shell.c
index 75c28dc..fd589e6 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -35,7 +35,7 @@
 #include <sys/wait.h>
 
 void shell_draw() {
-  char *full_path;
+  const char *full_path;
   int res;
 
   /* suspend ncurses mode */
@@ -52,7 +52,7 @@ void shell_draw() {
            "Press any key to continue.",
            full_path, res);
   } else {
-    char *shell = getenv("NCDU_SHELL");
+    const char *shell = getenv("NCDU_SHELL");
     if (shell == NULL) {
       shell = getenv("SHELL");
       if (shell == NULL)
diff --git a/src/util.c b/src/util.c
index 911dd87..6cf4080 100644
--- a/src/util.c
+++ b/src/util.c
@@ -62,7 +62,7 @@ char *cropstr(const char *from, int s) {
 }
 
 
-float formatsize(int64_t from, char **unit) {
+float formatsize(int64_t from, const char **unit) {
   float r = from;
   if (si) {
     if(r < 1000.0f)   { *unit = " B"; }
@@ -87,7 +87,7 @@ float formatsize(int64_t from, char **unit) {
 
 
 void printsize(enum ui_coltype t, int64_t from) {
-  char *unit;
+  const char *unit;
   float r = formatsize(from, &unit);
   uic_set(t == UIC_HD ? UIC_NUM_HD : t == UIC_SEL ? UIC_NUM_SEL : UIC_NUM);
   printw("%5.1f", r);
@@ -218,7 +218,7 @@ void nccreate(int height, int width, const char *title) {
 }
 
 
-void ncprint(int r, int c, char *fmt, ...) {
+void ncprint(int r, int c, const char *fmt, ...) {
   va_list arg;
   va_start(arg, fmt);
   move(subwinr+r, subwinc+c);
@@ -227,7 +227,7 @@ void ncprint(int r, int c, char *fmt, ...) {
 }
 
 
-void nctab(int c, int sel, int num, char *str) {
+void nctab(int c, int sel, int num, const char *str) {
   uic_set(sel ? UIC_KEY_HD : UIC_KEY);
   ncprint(0, c, "%d", num);
   uic_set(sel ? UIC_HD : UIC_DEFAULT);
@@ -355,7 +355,7 @@ void freedir(struct dir *dr) {
 }
 
 
-char *getpath(struct dir *cur) {
+const char *getpath(struct dir *cur) {
   static char *dat;
   static int datl = 0;
   struct dir *d, **list;
diff --git a/src/util.h b/src/util.h
index 34d6580..2c3e5ed 100644
--- a/src/util.h
+++ b/src/util.h
@@ -106,10 +106,10 @@ int ncresize(int, int);
 void nccreate(int, int, const char *);
 
 /* printf something somewhere in the last created window */
-void ncprint(int, int, char *, ...);
+void ncprint(int, int, const char *, ...);
 
 /* Add a "tab" to a window */
-void nctab(int, int, int, char *);
+void nctab(int, int, int, const char *);
 
 /* same as the w* functions of ncurses, with a color */
 #define ncaddstr(r, c, s) mvaddstr(subwinr+(r), subwinc+(c), s)
@@ -129,7 +129,7 @@ void nctab(int, int, int, char *);
 char *cropstr(const char *, int);
 
 /* Converts the given size in bytes into a float (0 <= f < 1000) and a unit string */
-float formatsize(int64_t, char **);
+float formatsize(int64_t, const char **);
 
 /* print size in the form of xxx.x XB */
 void printsize(enum ui_coltype, int64_t);
@@ -148,7 +148,7 @@ void freedir(struct dir *);
 
 /* generates full path from a dir item,
    returned pointer will be overwritten with a subsequent call */
-char *getpath(struct dir *);
+const char *getpath(struct dir *);
 
 /* returns the root element of the given dir struct */
 struct dir *getroot(struct dir *);
-- 
GitLab