From a07501a165e6f2521c9aa13fa63fab33cf67d876 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 17 Nov 2017 17:46:34 +0100 Subject: Declare non-local variables as const where possible Having non-const variables of static lifetime or even global scope is usually a bad idea. These variables are inherently constants, and this should be enforced. This required marking some functions as not modifying input parameters and marking some pointers as pointers to const. One advantage is that the compiler usually puts const static variables in a read-only code segment, so they can't be modified physically. This can be verified with `nm` (on POSIX systems). To avoid changes to the public API, functions returning non-const pointers to data tables were left intact, but the returned data may not be modified. Internally we prefer using the proj_list_* functions over the pj_get_*_ref functions, because the former return const pointers. --- src/pj_open_lib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pj_open_lib.c') diff --git a/src/pj_open_lib.c b/src/pj_open_lib.c index 08532beb..4eaefba1 100644 --- a/src/pj_open_lib.c +++ b/src/pj_open_lib.c @@ -38,7 +38,7 @@ static const char *(*pj_finder)(const char *) = NULL; static int path_count = 0; static char **search_path = NULL; -static char * proj_lib_name = +static const char * proj_lib_name = #ifdef PROJ_LIB PROJ_LIB; #else @@ -93,8 +93,8 @@ void pj_set_searchpath ( int count, const char **path ) /* just a couple of helper functions that lets other functions access the otherwise private search path */ -const char **proj_get_searchpath(void) { - return (const char **)search_path; +const char * const *proj_get_searchpath(void) { + return (const char * const *)search_path; } int proj_get_path_count(void) { -- cgit v1.2.3