]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Declare C string constants using array syntax
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Wed, 8 Dec 2021 20:07:00 +0000 (21:07 +0100)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 9 Apr 2022 10:04:24 +0000 (12:04 +0200)
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>
auth-globalprotect.c
gpst.c
http.c
library.c
main.c
openconnect-internal.h
ppp.c
version.sh

index bf6bc346929d8da429159c84d5e4894209b4288a..e8081610ba4e063caa05a78d2123cfa4cae7e3df 100644 (file)
@@ -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 b285ddde53df2331f29e97c3bc0eee4f8637c1f9..97c260bfd1bc54428cbd8b8de2c6991073862c3e 100644 (file)
--- 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 fc6538c16c2b839502249eec8d74edc718be6e73..3e7301f5185e19b715fa9f8109f2aa4d2afd6004 100644 (file)
--- 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"),
index 1f78ea14b7423df44af6e23975687d0b20ce9b74..1eb717dcb54f44bbde038776b891f94874345fe1 100644 (file)
--- 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 166121f2bce2b4649976da0429bfae0b7df71058..231f083091cfde5701835b5f825e46462675e136 100644 (file)
--- 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;
 
index 644f51bf0e88eef11dba6f60d41aa3298e32578a..c37cc712c5b4969d0e06141500f1f530f4494c09 100644 (file)
@@ -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 e8a52f751934a39959d6070ca501d00f2eed96b0..8c3f4f850c3dd8c0c67cbcf3fda94e575aac847b 100644 (file)
--- 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",
index 046895d487550679d925dea3cc189941c788e354..5ac5e5f93997c4d923ddac1b1f6322872a0d0e71 100755 (executable)
@@ -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"