Skip to content

Commit

Permalink
Avoid conflicting with HTSlib's kstring.c functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmarshall committed Mar 18, 2024
1 parent 139f68f commit b52164f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 5 additions & 7 deletions kstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
# include "malloc_wrap.h"
#endif

int ksprintf(kstring_t *s, const char *fmt, ...)
int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap)
{
va_list ap;
va_list ap2;
int l;
va_start(ap, fmt);
va_copy(ap2, ap);
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
va_end(ap);
if (l + 1 > s->m - s->l) {
s->m = s->l + l + 2;
kroundup32(s->m);
s->s = (char*)realloc(s->s, s->m);
va_start(ap, fmt);
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap2);
}
va_end(ap);
va_end(ap2);
s->l += l;
return l;
}
Expand Down
18 changes: 17 additions & 1 deletion kstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#ifdef USE_MALLOC_WRAPPERS
# include "malloc_wrap.h"
Expand Down Expand Up @@ -110,6 +111,21 @@ static inline int kputl(long c, kstring_t *s)
return 0;
}

int ksprintf(kstring_t *s, const char *fmt, ...);
int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap);

static inline int ksprintf(kstring_t *s, const char *fmt, ...)
{
va_list ap;
int l;
va_start(ap, fmt);
l = bwa_kvsprintf(s, fmt, ap);
va_end(ap);
return l;
}

static inline int kvsprintf(kstring_t *s, const char *fmt, va_list ap)
{
return bwa_kvsprintf(s, fmt, ap);
}

#endif

0 comments on commit b52164f

Please sign in to comment.