Skip to content

Commit fd93d2e

Browse files
peffgitster
authored andcommitted
argv-array: refactor empty_argv initialization
An empty argv-array is initialized to point to a static empty NULL-terminated array. The original implementation separates the actual storage of the NULL-terminator from the pointer to the list. This makes the exposed type a "const char **", which nicely matches the type stored by the argv-array. However, this indirection means that one cannot use empty_argv to initialize a static variable, since it is not a constant. Instead, we can expose empty_argv directly, as an array of pointers. The only place we use it is in the ARGV_ARRAY_INIT initializer, and it decays to a pointer appropriately there. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e52f56 commit fd93d2e

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

argv-array.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include "argv-array.h"
33
#include "strbuf.h"
44

5-
static const char *empty_argv_storage = NULL;
6-
const char **empty_argv = &empty_argv_storage;
5+
const char *empty_argv[] = { NULL };
76

87
void argv_array_init(struct argv_array *array)
98
{

argv-array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ARGV_ARRAY_H
22
#define ARGV_ARRAY_H
33

4-
extern const char **empty_argv;
4+
extern const char *empty_argv[];
55

66
struct argv_array {
77
const char **argv;

0 commit comments

Comments
 (0)