diff --git a/bin/ch-run.c b/bin/ch-run.c index 421bed954..99f5a6bf7 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -114,7 +114,6 @@ extern void warnings_reprint(void); const struct argp argp = { options, parse_opt, args_doc, usage }; extern char **environ; // see environ(7) extern char *warnings; -extern const size_t warnings_size; /** Main **/ @@ -126,7 +125,7 @@ int main(int argc, char *argv[]) int arg_next; char ** c_argv; - // initialze “warnings” buffer + // initialize “warnings” buffer warnings = mmap(NULL, warnings_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); diff --git a/bin/ch_misc.c b/bin/ch_misc.c index fd5443a2f..835edd120 100644 --- a/bin/ch_misc.c +++ b/bin/ch_misc.c @@ -42,20 +42,16 @@ char *host_tmp = NULL; char *username = NULL; /* List of warnings to be re-printed on exit. This is a buffer of shared memory - allocated by mmap(2), structured as a sequence of - null-terminated character strings. Warnings that do not fit in this buffer - will be lost, though we allocate enough memory that this is unlikely. See - “warnings_append()” for more details. */ + allocated by mmap(2), structured as a sequence of null-terminated character + strings. Warnings that do not fit in this buffer will be lost, though we + allocate enough memory that this is unlikely. See “warnings_append()” for + more details. */ char *warnings; /* Current byte offset from start of “warnings” buffer. This gives the address where the next appended string will start. */ size_t warnings_offset = 0; -/* Size of “warnings” buffer, in bytes. We want this to be big enough that we - don’t need to worry about running out of room. */ -const size_t warnings_size = 4096; - /** Function prototypes (private) **/ @@ -465,7 +461,8 @@ noreturn void msg_fatal(const char *file, int line, int errno_, void msgv(enum log_level level, const char *file, int line, int errno_, const char *fmt, va_list ap) { - char *message = ""; + char *message = NULL; + char *ap_msg = ""; if (level > verbose) return; @@ -487,7 +484,6 @@ void msgv(enum log_level level, const char *file, int line, int errno_, if (fmt == NULL) fmt = "please report this bug"; - char *ap_msg = ""; T_ (1 <= vasprintf(&ap_msg, fmt, ap)); T_ (1 <= asprintf(&message, "%s%s", message, ap_msg)); @@ -667,10 +663,10 @@ void version(void) fprintf(stderr, "%s\n", VERSION); } -/* Append null-terminated string “str” to the memory buffer “offset” bytes away - from the address pointed to by “addr”. Buffer should be “size” bytes long. - Return the number of bytes written. If there isn’t enough room for the - string, do nothing and return zero. */ +/* Append null-terminated string “str” to the memory buffer “offset” bytes after + from the address pointed to by “addr”. Buffer length is “size” bytes. Return + the number of bytes written. If there isn’t enough room for the string, do + nothing and return zero. */ size_t warnings_append(char *addr, char *str, size_t size, size_t offset) { size_t written = 0; diff --git a/bin/ch_misc.h b/bin/ch_misc.h index dbee38b4b..e74680c87 100644 --- a/bin/ch_misc.h +++ b/bin/ch_misc.h @@ -19,6 +19,11 @@ and hopefully others support the following extension. */ #define noreturn __attribute__ ((noreturn)) + +/* Size of “warnings” buffer, in bytes. We want this to be big enough that we + don’t need to worry about running out of room. */ +#define warnings_size 4096 + /* Test some value, and if it's not what we expect, exit with a fatal error. These are macros so we have access to the file and line number. @@ -105,7 +110,6 @@ extern char *host_tmp; extern char *username; extern char *warnings; extern size_t warnings_offset; -extern const size_t warnings_size; /** Function prototypes **/ diff --git a/lib/charliecloud.py b/lib/charliecloud.py index b9d4e2718..0e3cfaa62 100644 --- a/lib/charliecloud.py +++ b/lib/charliecloud.py @@ -119,7 +119,7 @@ class Download_Mode(enum.Enum): log_fp = sys.stderr # File object to print logs to. trace_fatal = False # Add abbreviated traceback to fatal error hint. -# Warnings to be re-printed when program exists +# Warnings to be re-printed when program exits warnings = [] # True if the download cache is enabled.