2004-11-25 20:51:53 +00:00
|
|
|
#include <stdarg.h>
|
2007-11-02 00:45:52 +00:00
|
|
|
#include <string.h>
|
2004-11-25 20:51:53 +00:00
|
|
|
#include "stralloc.h"
|
|
|
|
|
|
|
|
int stralloc_catm_internal(stralloc* sa, ...) {
|
|
|
|
va_list a;
|
|
|
|
const char* s;
|
2007-10-17 16:23:01 +00:00
|
|
|
size_t n=0;
|
|
|
|
va_start(a,sa);
|
2022-07-01 17:00:25 +00:00
|
|
|
while ((s=va_arg(a,const char*))) {
|
|
|
|
size_t tmp = strlen(s);
|
|
|
|
if (n + tmp < n) return 0; // integer overflow
|
|
|
|
// integer overflow should not be possible, but someone could pass
|
|
|
|
// the same string twice to provoke it. Better check than sorry.
|
|
|
|
n += tmp;
|
|
|
|
}
|
2007-10-17 16:23:01 +00:00
|
|
|
va_end(a);
|
|
|
|
stralloc_readyplus(sa,n);
|
|
|
|
|
2004-11-25 20:51:53 +00:00
|
|
|
va_start(a,sa);
|
|
|
|
while ((s=va_arg(a,const char*)))
|
|
|
|
if (stralloc_cats(sa,s)==0) {
|
|
|
|
va_end(a);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
va_end(a);
|
|
|
|
return 1;
|
|
|
|
}
|