]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: use const for read only pointers in ip{cmp,cpy}
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 13 Nov 2023 13:12:04 +0000 (14:12 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 24 Nov 2023 15:27:55 +0000 (16:27 +0100)
In this patch we fix the prototype for ipcmp() and ipcpy() functions so
that input pointers that are used exclusively for reads are used as const
pointers. This way, the compiler can safely assume that those variables
won't be altered by the function.

include/haproxy/tools.h
src/tools.c

index e3b847905faf7d5c2ec697034beabfb3174535d6..9fa431eb3713de74c5c62fec0a6b0c634cf27bd7 100644 (file)
@@ -782,7 +782,7 @@ extern int v6tov4(struct in_addr *sin_addr, struct in6_addr *sin6_addr);
  *  1 (false) if the addr is not the same in both
  *  -1 (unable) if one of the addr is not AF_INET*
  */
-int ipcmp(struct sockaddr_storage *ss1, struct sockaddr_storage *ss2, int check_port);
+int ipcmp(const struct sockaddr_storage *ss1, const struct sockaddr_storage *ss2, int check_port);
 
 /* compare a struct sockaddr_storage to a struct net_addr and return :
  *  0 (true)  if <addr> is matching <net>
@@ -795,7 +795,7 @@ int ipcmp2net(const struct sockaddr_storage *addr, const struct net_addr *net);
  * the caller must clear <dest> before calling.
  * Returns a pointer to the destination
  */
-struct sockaddr_storage *ipcpy(struct sockaddr_storage *source, struct sockaddr_storage *dest);
+struct sockaddr_storage *ipcpy(const struct sockaddr_storage *source, struct sockaddr_storage *dest);
 
 char *human_time(int t, short hz_div);
 
index f6aff14b323293cf1b6362cec0d1d9d69d5d9bb7..a7f4ff13c7b7edd6292683d2c1ff9adae749e43c 100644 (file)
@@ -3382,7 +3382,7 @@ int v6tov4(struct in_addr *sin_addr, struct in6_addr *sin6_addr)
  *  1 (false) if the addr is not the same in both
  *  -1 (unable) if one of the addr is not AF_INET*
  */
-int ipcmp(struct sockaddr_storage *ss1, struct sockaddr_storage *ss2, int check_port)
+int ipcmp(const struct sockaddr_storage *ss1, const struct sockaddr_storage *ss2, int check_port)
 {
        if ((ss1->ss_family != AF_INET) && (ss1->ss_family != AF_INET6))
                return -1;
@@ -3450,7 +3450,7 @@ int ipcmp2net(const struct sockaddr_storage *addr, const struct net_addr *net)
  * it is preserved, so that this function can be used to switch to another
  * address family with no risk. Returns a pointer to the destination.
  */
-struct sockaddr_storage *ipcpy(struct sockaddr_storage *source, struct sockaddr_storage *dest)
+struct sockaddr_storage *ipcpy(const struct sockaddr_storage *source, struct sockaddr_storage *dest)
 {
        int prev_port;