386915fb7bdbae22f8ed152174d8b8635524c1b2 galt Sun Oct 28 00:51:33 2018 -0700 code review fixes to hgBlat Search ALL. refs #22251 diff --git src/lib/common.c src/lib/common.c index 17debeb..ac691e5 100644 --- src/lib/common.c +++ src/lib/common.c @@ -3404,43 +3404,38 @@ } void safencat(char *buf, size_t bufSize, const char *src, size_t n) /* append n characters from a string to a buffer, with bounds checking. */ { size_t blen = strlen(buf); if (blen+n > bufSize-1) errAbort("buffer overflow, size %lld, new string size: %lld", (long long)bufSize, (long long)(blen+n)); size_t slen = strlen(src); if (slen > n) slen = n; strncat(buf, src, n); buf[blen+slen] = '\0'; } -void safecatRepeatChar(char *buf, size_t bufSize, const char c, int n) -/* Append a character to a buffer, n times with bounds checking.*/ +void safememset(char *buf, size_t bufSize, const char c, size_t n) +/* Append a character to a buffer repeatedly, n times with bounds checking.*/ { -if (n < 0) - errAbort("safecatRepeatChar called with invalid negative count %d", n); size_t blen = strlen(buf); -size_t slen = n; -if (blen+slen > bufSize-1) - errAbort("buffer overflow, size %lld, new string size: %lld", (long long)bufSize, (long long)(blen+slen)); -int i; -for(i=0; i < slen; ++i) - buf[blen+i] = c; -buf[blen+slen] = 0; +if (blen+n+1 > bufSize) + errAbort("buffer overflow, size %lld, new string size: %lld", (long long)bufSize, (long long)(blen+n)); +memset(buf+blen, c, n); +buf[blen+n] = 0; } static char *naStr = "n/a"; static char *emptyStr = ""; char *naForNull(char *s) /* Return 'n/a' if s is NULL, otherwise s. */ { if (s == NULL) s = naStr; return s; } char *naForEmpty(char *s)