From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Wed, 8 Dec 2021 20:07:00 +0000 (+0100) Subject: Declare C string constants using array syntax X-Git-Tag: v9.00~63^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c58464a8bdf99de27e0729377de652cbc937da00;p=users%2Fdwmw2%2Fopenconnect.git Declare C string constants using array syntax Avoid pointer syntax when possible. They are different, the array syntax generates smaller, faster code. See for example: https://eklitzke.org/declaring-c-string-constants-the-right-way Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> --- diff --git a/auth-globalprotect.c b/auth-globalprotect.c index bf6bc346..e8081610 100644 --- a/auth-globalprotect.c +++ b/auth-globalprotect.c @@ -604,7 +604,6 @@ static int gpst_login(struct openconnect_info *vpninfo, int portal, struct login { int result, blind_retry = 0; struct oc_text_buf *request_body = buf_alloc(); - const char *request_body_type = "application/x-www-form-urlencoded"; char *xml_buf = NULL, *orig_path; /* Ask the user to fill in the auth form; repeat as necessary */ @@ -685,7 +684,7 @@ static int gpst_login(struct openconnect_info *vpninfo, int portal, struct login orig_path = vpninfo->urlpath; vpninfo->urlpath = strdup(portal ? "global-protect/getconfig.esp" : "ssl-vpn/login.esp"); - result = do_https_request(vpninfo, "POST", request_body_type, request_body, &xml_buf, NULL, HTTP_NO_FLAGS); + result = do_https_request(vpninfo, "POST", "application/x-www-form-urlencoded", request_body, &xml_buf, NULL, HTTP_NO_FLAGS); free(vpninfo->urlpath); vpninfo->urlpath = orig_path; @@ -775,8 +774,6 @@ int gpst_bye(struct openconnect_info *vpninfo, const char *reason) char *orig_path; int result; struct oc_text_buf *request_body = buf_alloc(); - const char *request_body_type = "application/x-www-form-urlencoded"; - const char *method = "POST"; char *xml_buf = NULL; /* In order to logout successfully, the client must send not only @@ -801,7 +798,7 @@ int gpst_bye(struct openconnect_info *vpninfo, const char *reason) orig_path = vpninfo->urlpath; vpninfo->urlpath = strdup("ssl-vpn/logout.esp"); openconnect_close_https(vpninfo, 0); - result = do_https_request(vpninfo, method, request_body_type, request_body, &xml_buf, NULL, HTTP_NO_FLAGS); + result = do_https_request(vpninfo, "POST", "application/x-www-form-urlencoded", request_body, &xml_buf, NULL, HTTP_NO_FLAGS); free(vpninfo->urlpath); vpninfo->urlpath = orig_path; diff --git a/gpst.c b/gpst.c index b285ddde..97c260bf 100644 --- a/gpst.c +++ b/gpst.c @@ -612,8 +612,6 @@ static int gpst_get_config(struct openconnect_info *vpninfo) struct oc_text_buf *request_body = buf_alloc(); const char *old_addr = vpninfo->ip_info.addr; const char *old_addr6 = vpninfo->ip_info.addr6; - const char *request_body_type = "application/x-www-form-urlencoded"; - const char *method = "POST"; char *xml_buf = NULL; @@ -635,7 +633,7 @@ static int gpst_get_config(struct openconnect_info *vpninfo) orig_path = vpninfo->urlpath; vpninfo->urlpath = strdup("ssl-vpn/getconfig.esp"); - result = do_https_request(vpninfo, method, request_body_type, request_body, &xml_buf, NULL, HTTP_NO_FLAGS); + result = do_https_request(vpninfo, "POST", "application/x-www-form-urlencoded", request_body, &xml_buf, NULL, HTTP_NO_FLAGS); free(vpninfo->urlpath); vpninfo->urlpath = orig_path; @@ -840,8 +838,6 @@ static int check_or_submit_hip_report(struct openconnect_info *vpninfo, const ch int result; struct oc_text_buf *request_body = buf_alloc(); - const char *request_body_type = "application/x-www-form-urlencoded"; - const char *method = "POST"; char *xml_buf=NULL, *orig_path; /* cookie gives us these fields: authcookie, portal, user, domain, computer, and (maybe the unnecessary) preferred-ip/ipv6 */ @@ -865,7 +861,7 @@ static int check_or_submit_hip_report(struct openconnect_info *vpninfo, const ch orig_path = vpninfo->urlpath; vpninfo->urlpath = strdup(report ? "ssl-vpn/hipreport.esp" : "ssl-vpn/hipreportcheck.esp"); - result = do_https_request(vpninfo, method, request_body_type, request_body, &xml_buf, NULL, HTTP_NO_FLAGS); + result = do_https_request(vpninfo, "POST", "application/x-www-form-urlencoded", request_body, &xml_buf, NULL, HTTP_NO_FLAGS); free(vpninfo->urlpath); vpninfo->urlpath = orig_path; diff --git a/http.c b/http.c index fc6538c1..3e7301f5 100644 --- a/http.c +++ b/http.c @@ -998,7 +998,7 @@ static int proxy_read(struct openconnect_info *vpninfo, char *buf, size_t len) return cancellable_recv(vpninfo, vpninfo->proxy_fd, buf, len); } -static const char *socks_errors[] = { +static const char * const socks_errors[] = { N_("request granted"), N_("general failure"), N_("connection not allowed by ruleset"), diff --git a/library.c b/library.c index 1f78ea14..1eb717dc 100644 --- a/library.c +++ b/library.c @@ -380,7 +380,7 @@ int openconnect_make_cstp_connection(struct openconnect_info *vpninfo) int openconnect_set_reported_os(struct openconnect_info *vpninfo, const char *os) { - const char *allowed[] = {"linux", "linux-64", "win", "mac-intel", "android", "apple-ios"}; + static const char * const allowed[] = {"linux", "linux-64", "win", "mac-intel", "android", "apple-ios"}; if (!os) { #if defined(__APPLE__) @@ -1349,7 +1349,7 @@ int openconnect_setup_tun_device(struct openconnect_info *vpninfo, return openconnect_setup_tun_fd(vpninfo, tun_fd); } -static const char *compr_name_map[] = { +static const char * const compr_name_map[] = { [COMPR_DEFLATE] = "Deflate", [COMPR_LZS] = "LZS", [COMPR_LZ4] = "LZ4", diff --git a/main.c b/main.c index 166121f2..231f0830 100644 --- a/main.c +++ b/main.c @@ -658,7 +658,7 @@ static void helpmessage(void) static void print_build_opts(void) { - const char *comma = ", ", *sep = comma + 1; + const char comma[] = ", ", *sep = comma + 1; printf(_("Using %s. Features present:"), openconnect_get_tls_library_version()); @@ -717,7 +717,7 @@ static void print_build_opts(void) static void print_supported_protocols(void) { - const char *comma = ", ", *sep = comma + 1; + const char comma[] = ", ", *sep = comma + 1; struct oc_vpn_proto *protos, *p; int n; diff --git a/openconnect-internal.h b/openconnect-internal.h index 644f51bf..c37cc712 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -1574,7 +1574,7 @@ int process_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *for void openconnect_set_juniper(struct openconnect_info *vpninfo); /* version.c */ -extern const char *openconnect_version_str; +extern const char openconnect_version_str[]; static inline int certinfo_is_primary(struct cert_info *certinfo) diff --git a/ppp.c b/ppp.c index e8a52f75..8c3f4f85 100644 --- a/ppp.c +++ b/ppp.c @@ -157,7 +157,7 @@ static int unhdlc_in_place(struct openconnect_info *vpninfo, unsigned char *byte } } -static const char *ppps_names[] = { +static const char * const ppps_names[] = { "DEAD", "ESTABLISH", "OPENED", @@ -166,7 +166,7 @@ static const char *ppps_names[] = { "TERMINATE" }; -static const char *encap_names[PPP_ENCAP_MAX+1] = { +static const char * const encap_names[PPP_ENCAP_MAX+1] = { NULL, "RFC1661", "RFC1662 HDLC", @@ -175,7 +175,7 @@ static const char *encap_names[PPP_ENCAP_MAX+1] = { "FORTINET", }; -static const char *lcp_names[] = { +static const char * const lcp_names[] = { NULL, "Configure-Request", "Configure-Ack", diff --git a/version.sh b/version.sh index 046895d4..5ac5e5f9 100755 --- a/version.sh +++ b/version.sh @@ -17,5 +17,5 @@ else # XXX: Equivalent for .deb packages? v="$v"-unknown fi -echo "const char *openconnect_version_str = \"$v\";" > $1 +echo "const char openconnect_version_str[] = \"$v\";" > $1 echo "New version: $v"