X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/f2d4f32f6dd5a586d0f160a34467cdc8b9151317..4ecdd9dda778478a2d3244cfc349df69a4224f96:/sbr/charstring.c?ds=sidebyside diff --git a/sbr/charstring.c b/sbr/charstring.c index d94961aa..589b000e 100644 --- a/sbr/charstring.c +++ b/sbr/charstring.c @@ -1,5 +1,4 @@ -/* - * charstring -- dynamically-sized char array that can report size +/* charstring.c -- dynamically-sized char array that can report size * in both characters and bytes * * This code is Copyright (c) 2014, by the authors of nmh. See the @@ -42,8 +41,9 @@ charstring_reserve (charstring_t s, size_t need) { */ charstring_t charstring_create (size_t max) { - charstring_t s = mh_xmalloc (sizeof *s); + charstring_t s; + NEW(s); s->max = NMH_MAX_CHARWIDTH * (max ? max : CHARSTRING_DEFAULT_SIZE); s->cur = s->buffer = mh_xmalloc (s->max); s->chars = 0; @@ -54,8 +54,9 @@ charstring_create (size_t max) { charstring_t charstring_copy (const charstring_t src) { const size_t num = src->cur - src->buffer; - charstring_t s = mh_xmalloc (sizeof *s); + charstring_t s; + NEW(s); s->max = src->max; s->buffer = mh_xmalloc (s->max); memcpy (s->buffer, src->buffer, num); @@ -179,8 +180,8 @@ charstring_last_char_len (const charstring_t s) { len = mbtowc (&wide_char, sp, (size_t) MB_CUR_MAX < remaining ? (size_t) MB_CUR_MAX : remaining); - sp += len > 0 ? len : 1; - remaining -= len > 0 ? len : 1; + sp += max(len, 1); + remaining -= max(len, 1); } #else /* ! MULTIBYTE_SUPPORT */ if (charstring_bytes (s) > 0) { len = 1; }