Skip to content

Commit e69bf8c

Browse files
committed
Avoid conflicting with HTSlib's kstring.c functions
Make ksprintf() static inline in kstring.h, so that it (like the other bwa/kstring.h functions) won't conflict with similar HTSlib functions. Instead implement it and kvsprintf() in terms of a new bwa_kvsprintf() function. Fixes samtools/htslib#693.
1 parent 2d4272b commit e69bf8c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

kstring.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66
# include "malloc_wrap.h"
77
#endif
88

9-
int ksprintf(kstring_t *s, const char *fmt, ...)
9+
int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap)
1010
{
11-
va_list ap;
11+
va_list ap2;
1212
int l;
13-
va_start(ap, fmt);
13+
va_copy(ap2, ap);
1414
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
15-
va_end(ap);
1615
if (l + 1 > s->m - s->l) {
1716
s->m = s->l + l + 2;
1817
kroundup32(s->m);
1918
s->s = (char*)realloc(s->s, s->m);
20-
va_start(ap, fmt);
21-
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
19+
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap2);
2220
}
23-
va_end(ap);
21+
va_end(ap2);
2422
s->l += l;
2523
return l;
2624
}

kstring.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stdlib.h>
55
#include <string.h>
6+
#include <stdarg.h>
67

78
#ifdef USE_MALLOC_WRAPPERS
89
# include "malloc_wrap.h"
@@ -110,6 +111,21 @@ static inline int kputl(long c, kstring_t *s)
110111
return 0;
111112
}
112113

113-
int ksprintf(kstring_t *s, const char *fmt, ...);
114+
int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap);
115+
116+
static inline int ksprintf(kstring_t *s, const char *fmt, ...)
117+
{
118+
va_list ap;
119+
int l;
120+
va_start(ap, fmt);
121+
l = bwa_kvsprintf(s, fmt, ap);
122+
va_end(ap);
123+
return l;
124+
}
125+
126+
static inline int kvsprintf(kstring_t *s, const char *fmt, va_list ap)
127+
{
128+
return bwa_kvsprintf(s, fmt, ap);
129+
}
114130

115131
#endif

0 commit comments

Comments
 (0)