- fix memory allocation botch in wide strings
- check mbstowcs return code
This commit is contained in:
parent
e63c844a17
commit
0c0f23399c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chartype.c,v 1.5 2011/07/27 02:18:30 christos Exp $ */
|
||||
/* $NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
#include "config.h"
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
__RCSID("$NetBSD: chartype.c,v 1.5 2011/07/27 02:18:30 christos Exp $");
|
||||
__RCSID("$NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $");
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include "el.h"
|
||||
#include <stdlib.h>
|
||||
|
@ -52,7 +52,7 @@ ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize)
|
|||
void *p;
|
||||
if (mincsize > conv->csize) {
|
||||
conv->csize = mincsize;
|
||||
p = el_realloc(conv->cbuff, conv->csize);
|
||||
p = el_realloc(conv->cbuff, conv->csize * sizeof(char));
|
||||
if (p == NULL) {
|
||||
conv->csize = 0;
|
||||
el_free(conv->cbuff);
|
||||
|
@ -63,7 +63,7 @@ ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize)
|
|||
|
||||
if (minwsize > conv->wsize) {
|
||||
conv->wsize = minwsize;
|
||||
p = el_realloc(conv->wbuff, conv->wsize);
|
||||
p = el_realloc(conv->wbuff, conv->wsize * sizeof(Char));
|
||||
if (p == NULL) {
|
||||
conv->wsize = 0;
|
||||
el_free(conv->wbuff);
|
||||
|
@ -119,7 +119,9 @@ ct_decode_string(const char *s, ct_buffer_t *conv)
|
|||
if (!conv->wbuff)
|
||||
return NULL;
|
||||
|
||||
len = ct_mbstowcs(0, s, 0);
|
||||
len = ct_mbstowcs(NULL, s, 0);
|
||||
if (len == (size_t)-1)
|
||||
return NULL;
|
||||
if (len > conv->wsize)
|
||||
ct_conv_buff_resize(conv, 0, len + 1);
|
||||
if (!conv->wbuff)
|
||||
|
|
Loading…
Reference in New Issue