From ba7f7cc783672784bebc6e69349b55c6c75c1973 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 27 Sep 2015 18:35:27 -0700 Subject: [PATCH] Convert src/xlibi18n to use reallocarray() Signed-off-by: Alan Coopersmith --- src/xlibi18n/ICWrap.c | 3 ++- src/xlibi18n/XDefaultIMIF.c | 3 ++- src/xlibi18n/XlcDL.c | 8 +++++--- src/xlibi18n/lcDB.c | 3 ++- src/xlibi18n/lcGeneric.c | 27 ++++++++++++++------------- src/xlibi18n/lcPrTxt.c | 7 ++++--- src/xlibi18n/lcWrap.c | 3 ++- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/xlibi18n/ICWrap.c b/src/xlibi18n/ICWrap.c index 69f080d8..bc53710d 100644 --- a/src/xlibi18n/ICWrap.c +++ b/src/xlibi18n/ICWrap.c @@ -66,6 +66,7 @@ from The Open Group. #endif #include "Xlibint.h" #include "Xlcint.h" +#include "reallocarray.h" static int _XIMNestedListToNestedList( @@ -128,7 +129,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return) return; } - args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg)); + args = Xmallocarray((unsigned)max_count + 1, sizeof(XIMArg)); *args_return = args; if (!args) return; diff --git a/src/xlibi18n/XDefaultIMIF.c b/src/xlibi18n/XDefaultIMIF.c index 7c32ce29..557aa494 100644 --- a/src/xlibi18n/XDefaultIMIF.c +++ b/src/xlibi18n/XDefaultIMIF.c @@ -67,6 +67,7 @@ Sun Microsystems, Inc. or its licensors is granted. #include "Xlibint.h" #include "Xlcint.h" #include "XlcGeneric.h" +#include "reallocarray.h" #ifndef MAXINT #define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1)) @@ -266,7 +267,7 @@ _GetIMValues( *(XIMStyles **)p->value = styles; styles->count_styles = 1; styles->supported_styles = - Xmalloc(styles->count_styles * sizeof(XIMStyle)); + Xmallocarray(styles->count_styles, sizeof(XIMStyle)); styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone); } else { break; diff --git a/src/xlibi18n/XlcDL.c b/src/xlibi18n/XlcDL.c index bc71900a..c1abe79f 100644 --- a/src/xlibi18n/XlcDL.c +++ b/src/xlibi18n/XlcDL.c @@ -85,6 +85,7 @@ Sun Microsystems, Inc. or its licensors is granted. #include "Xlibint.h" #include "XlcPublic.h" #include "XlcPubI.h" +#include "reallocarray.h" #define XI18N_DLREL 2 @@ -185,7 +186,7 @@ resolve_object(char *path, const char *lc_name) if (lc_len == 0) { /* True only for the 1st time */ lc_len = OBJECT_INIT_LEN; - xi18n_objects_list = Xmalloc(sizeof(XI18NObjectsListRec) * lc_len); + xi18n_objects_list = Xmallocarray(lc_len, sizeof(XI18NObjectsListRec)); if (!xi18n_objects_list) return; } snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS"); @@ -207,8 +208,9 @@ resolve_object(char *path, const char *lc_name) if (lc_count == lc_len) { int new_len = lc_len + OBJECT_INC_LEN; - XI18NObjectsListRec *tmp = Xrealloc(xi18n_objects_list, - sizeof(XI18NObjectsListRec) * new_len); + XI18NObjectsListRec *tmp = + Xreallocarray(xi18n_objects_list, new_len, + sizeof(XI18NObjectsListRec)); if (tmp == NULL) goto done; xi18n_objects_list = tmp; diff --git a/src/xlibi18n/lcDB.c b/src/xlibi18n/lcDB.c index 19e80aa2..e04a5d89 100644 --- a/src/xlibi18n/lcDB.c +++ b/src/xlibi18n/lcDB.c @@ -39,6 +39,7 @@ #include #include "Xlibint.h" #include "XlcPubI.h" +#include "reallocarray.h" #else /* NOT_X_ENV */ @@ -492,7 +493,7 @@ append_value_list (void) char **prev_list = value_list; value_list = (char **) - Xrealloc(value_list, sizeof(char *) * (value_num + 2)); + Xreallocarray(value_list, value_num + 2, sizeof(char *)); if (value_list == NULL) { Xfree(prev_list); } diff --git a/src/xlibi18n/lcGeneric.c b/src/xlibi18n/lcGeneric.c index f816fee7..fc17841a 100644 --- a/src/xlibi18n/lcGeneric.c +++ b/src/xlibi18n/lcGeneric.c @@ -34,6 +34,7 @@ #include #include "Xlibint.h" #include "XlcGeneric.h" +#include "reallocarray.h" static XLCd create (const char *name, XLCdMethods methods); static Bool initialize (XLCd lcd); @@ -157,8 +158,8 @@ add_charset( int num; if ((num = codeset->num_charsets)) - new_list = Xrealloc(codeset->charset_list, - (num + 1) * sizeof(XlcCharSet)); + new_list = Xreallocarray(codeset->charset_list, + num + 1, sizeof(XlcCharSet)); else new_list = Xmalloc(sizeof(XlcCharSet)); @@ -184,8 +185,8 @@ add_codeset( return NULL; if ((num = gen->codeset_num)) - new_list = Xrealloc(gen->codeset_list, - (num + 1) * sizeof(CodeSet)); + new_list = Xreallocarray(gen->codeset_list, + num + 1, sizeof(CodeSet)); else new_list = Xmalloc(sizeof(CodeSet)); @@ -231,8 +232,8 @@ add_parse_list( } if ((num = gen->mb_parse_list_num)) - new_list = Xrealloc(gen->mb_parse_list, - (num + 2) * sizeof(ParseInfo)); + new_list = Xreallocarray(gen->mb_parse_list, + num + 2, sizeof(ParseInfo)); else { new_list = Xmalloc(2 * sizeof(ParseInfo)); } @@ -350,7 +351,7 @@ _XlcParse_scopemaps( const char *str_sc; num = count_scopemap(str); - scope = Xmalloc(num * sizeof(FontScopeRec)); + scope = Xmallocarray(num, sizeof(FontScopeRec)); if (scope == NULL) return NULL; @@ -535,8 +536,8 @@ add_conversion( int num; if ((num = gen->segment_conv_num) > 0) { - new_list = Xrealloc(gen->segment_conv, - (num + 1) * sizeof(SegConvRec)); + new_list = Xreallocarray(gen->segment_conv, + num + 1, sizeof(SegConvRec)); } else { new_list = Xmalloc(sizeof(SegConvRec)); } @@ -667,7 +668,7 @@ create_ctextseg( ret->side = XlcGLGR; strcpy(cset_name,ret->name); } - ret->area = Xmalloc((num - 1)*sizeof(FontScopeRec)); + ret->area = Xmallocarray(num - 1, sizeof(FontScopeRec)); if (ret->area == NULL) { Xfree (cset_name); Xfree (ret->name); @@ -870,8 +871,8 @@ load_generic( codeset->byteM = NULL; break ; } - codeset->byteM = Xmalloc( - (codeset->length)*sizeof(ByteInfoListRec)); + codeset->byteM = Xmallocarray(codeset->length, + sizeof(ByteInfoListRec)); if (codeset->byteM == NULL) { goto err; } @@ -882,7 +883,7 @@ load_generic( (codeset->byteM)[M-1].M = M; (codeset->byteM)[M-1].byteinfo_num = num; (codeset->byteM)[M-1].byteinfo = - Xmalloc(num * sizeof(ByteInfoRec)); + Xmallocarray(num, sizeof(ByteInfoRec)); for (ii = 0 ; ii < num ; ii++) { tmpb = (codeset->byteM)[M-1].byteinfo ; /* default 0x00 - 0xff */ diff --git a/src/xlibi18n/lcPrTxt.c b/src/xlibi18n/lcPrTxt.c index 77afd937..5ab5ad4a 100644 --- a/src/xlibi18n/lcPrTxt.c +++ b/src/xlibi18n/lcPrTxt.c @@ -30,6 +30,7 @@ #include "XlcPubI.h" #include #include +#include "reallocarray.h" static XPointer * alloc_list( @@ -40,11 +41,11 @@ alloc_list( if (is_wide_char) { wchar_t **wstr_list; - wstr_list = Xmalloc(count * sizeof(wchar_t *)); + wstr_list = Xmallocarray(count, sizeof(wchar_t *)); if (wstr_list == NULL) return (XPointer *) NULL; - *wstr_list = Xmalloc(nitems * sizeof(wchar_t)); + *wstr_list = Xmallocarray(nitems, sizeof(wchar_t)); if (*wstr_list == NULL) { Xfree(wstr_list); return (XPointer *) NULL; @@ -54,7 +55,7 @@ alloc_list( } else { char **str_list; - str_list = Xmalloc(count * sizeof(char *)); + str_list = Xmallocarray(count, sizeof(char *)); if (str_list == NULL) return (XPointer *) NULL; diff --git a/src/xlibi18n/lcWrap.c b/src/xlibi18n/lcWrap.c index 38242608..f2af2401 100644 --- a/src/xlibi18n/lcWrap.c +++ b/src/xlibi18n/lcWrap.c @@ -66,6 +66,7 @@ from The Open Group. #endif #include #include "XlcPubI.h" +#include "reallocarray.h" #ifdef XTHREADS LockInfoPtr _Xi18n_lock; @@ -564,7 +565,7 @@ _XlcVaToArgList( { XlcArgList args; - *args_ret = args = Xmalloc(sizeof(XlcArg) * count); + *args_ret = args = Xmallocarray(count, sizeof(XlcArg)); if (args == (XlcArgList) NULL) return;