/* sb.c - string buffer manipulation routines
- Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007, 2009, 2012
- Free Software Foundation, Inc.
+ Copyright (C) 1994-2020 Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
void
sb_build (sb *ptr, size_t size)
{
- ptr->ptr = xmalloc (size + 1);
+ ptr->ptr = XNEWVEC (char, size + 1);
ptr->max = size;
ptr->len = 0;
}
{
sb_to_scrub = s;
scrub_position = s->ptr;
-
+
sb_check (ptr, s->len);
ptr->len += do_scrub_chars (scrub_from_sb, ptr->ptr + ptr->len, s->len);
if ((ssize_t) want < 0)
as_fatal ("string buffer overflow");
#if GCC_VERSION >= 3004
- max = (size_t) 1 << (CHAR_BIT * sizeof (want) - __builtin_clzl (want));
+ max = (size_t) 1 << (CHAR_BIT * sizeof (want)
+ - (sizeof (want) <= sizeof (long)
+ ? __builtin_clzl ((long) want)
+ : __builtin_clzll ((long long) want)));
#else
max = 128;
while (want > max)
#endif
max -= MALLOC_OVERHEAD + 1;
ptr->max = max;
- ptr->ptr = xrealloc (ptr->ptr, max + 1);
+ ptr->ptr = XRESIZEVEC (char, ptr->ptr, max + 1);
}
}