--- rxvt-unicode/src/misc.C 2007/09/08 21:25:56 1.46 +++ rxvt-unicode/src/misc.C 2008/04/26 03:37:18 1.52 @@ -40,7 +40,10 @@ ssize_t l = wcrtomb (dst, *str++, mbs); if (l < 0) - *dst++ = '?'; + { + *dst++ = '?'; + wcrtomb (0, 0, mbs); // reset undefined state + } else dst += l; } @@ -81,7 +84,7 @@ *p++ = 0xc0 | ( w >> 6), *p++ = 0x80 | ( w & 0x3f); else if (w < 0x010000) - *p++ = 0xe0 | ( w >> 12 ), + *p++ = 0xe0 | ( w >> 12), *p++ = 0x80 | ((w >> 6) & 0x3f), *p++ = 0x80 | ( w & 0x3f); else if (w < 0x110000) @@ -118,7 +121,7 @@ else if (s[0] < 0x80) *p++ = *s++; else if (len >= 2 - && s[0] >= 0xc2 && s[0] <= 0xdf + && s[0] >= 0xc2 && s[0] <= 0xdf && (s[1] & 0xc0) == 0x80) { *p++ = ((s[0] & 0x1f) << 6) @@ -146,9 +149,9 @@ && (s[2] & 0xc0) == 0x80 && (s[3] & 0xc0) == 0x80) { - *p++ = ((s[0] & 0x07) << 18) - | ((s[1] & 0x3f) << 12) - | ((s[2] & 0x3f) << 6) + *p++ = ((s[0] & 0x07) << 18) + | ((s[1] & 0x3f) << 12) + | ((s[2] & 0x3f) << 6) | (s[3] & 0x3f); s += 4; } @@ -237,7 +240,7 @@ /* * remove leading/trailing space in place. */ -char * +char * rxvt_strtrim (char *str) NOTHROW { char *r, *s; @@ -264,9 +267,8 @@ /* * Split a comma-separated string into an array, stripping leading and * trailing spaces from each entry. Empty strings are properly returned - * Caller should free each entry and array when done */ -char ** +char ** rxvt_splitcommastring (const char *cs) NOTHROW { int l, n, p; @@ -288,7 +290,7 @@ for ( ; *t && *t != ','; t++) ; p = t - s; ret[l] = (char *)malloc (p + 1); - strncpy (ret[l], s, p); + memcpy (ret[l], s, p); ret[l][p] = '\0'; rxvt_strtrim (ret[l]); s = ++t; @@ -306,5 +308,35 @@ free (cs); } +void * +rxvt_malloc (size_t size) +{ + void *p = malloc (size); + + if (!p) + rxvt_fatal ("memory allocation failure. aborting.\n"); + + return p; +} +void * +rxvt_calloc (size_t number, size_t size) +{ + void *p = calloc (number, size); + if (!p) + rxvt_fatal ("memory allocation failure. aborting.\n"); + + return p; +} + +void * +rxvt_realloc (void *ptr, size_t size) +{ + void *p = realloc (ptr, size); + + if (!p) + rxvt_fatal ("memory allocation failure. aborting.\n"); + + return p; +}