Unverified Commit dcd6f810 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

snprintf: renamed and we now only use msnprintf()

The function does not return the same value as snprintf() normally does,
so readers may be mislead into thinking the code works differently than
it actually does. A different function name makes this easier to detect.

Reported-by: Tomas Hoger
Assisted-by: Daniel Gustafsson
Fixes #3296
Closes #3297
parent 9944d6ba
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,4 +62,4 @@ include Makefile.inc
all: $(check_PROGRAMS)

checksrc:
	@PERL@ $(top_srcdir)/lib/checksrc.pl $(srcdir)/*.c
	@PERL@ $(top_srcdir)/lib/checksrc.pl -ASNPRINTF $(srcdir)/*.c
+2 −2
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
  char service[12];
  int rc;

  snprintf(service, sizeof(service), "%d", tsd->port);
  msnprintf(service, sizeof(service), "%d", tsd->port);

  rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res);

@@ -679,7 +679,7 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
  hints.ai_family = pf;
  hints.ai_socktype = conn->socktype;

  snprintf(sbuf, sizeof(sbuf), "%d", port);
  msnprintf(sbuf, sizeof(sbuf), "%d", port);

  reslv->start = Curl_now();
  /* fire up a new resolver thread! */
+13 −13
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
@@ -233,20 +233,20 @@ static CURLcode base64_encode(const char *table64,

    switch(inputparts) {
    case 1: /* only one byte read */
      snprintf(output, 5, "%c%c==",
      msnprintf(output, 5, "%c%c==",
                table64[obuf[0]],
                table64[obuf[1]]);
      break;

    case 2: /* two bytes read */
      snprintf(output, 5, "%c%c%c=",
      msnprintf(output, 5, "%c%c%c=",
                table64[obuf[0]],
                table64[obuf[1]],
                table64[obuf[2]]);
      break;

    default:
      snprintf(output, 5, "%c%c%c%c",
      msnprintf(output, 5, "%c%c%c%c",
                table64[obuf[0]],
                table64[obuf[1]],
                table64[obuf[2]],
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ static void hashkey(struct connectdata *conn, char *buf,
  DEBUGASSERT(len > 32);

  /* put the number first so that the hostname gets cut off if too long */
  snprintf(buf, len, "%ld%s", conn->port, hostname);
  msnprintf(buf, len, "%ld%s", conn->port, hostname);
}

void Curl_conncache_unlock(struct connectdata *conn)
+1 −1
Original line number Diff line number Diff line
@@ -655,7 +655,7 @@ bool Curl_getaddressinfo(struct sockaddr *sa, char *addr,
#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
    case AF_UNIX:
      su = (struct sockaddr_un*)sa;
      snprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
      msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
      *port = 0;
      return TRUE;
#endif
Loading