a7088ea8bd1828450e85dca8a04b937e7bd38ca1 galt Mon Oct 8 12:38:24 2018 -0700 Sqashed BLAT ALl Genomes branch diff --git src/lib/common.c src/lib/common.c index 20fa22a..da64277 100644 --- src/lib/common.c +++ src/lib/common.c @@ -3368,30 +3368,45 @@ } 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.*/ +{ +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; +} + 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) /* Return n/a if s is "" or NULL, otherwise s. */ {