Commit ba7f7cc7 authored by Alan Coopersmith's avatar Alan Coopersmith

Convert src/xlibi18n to use reallocarray()

Signed-off-by: Alan Coopersmith's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
parent 336c1e7a
...@@ -66,6 +66,7 @@ from The Open Group. ...@@ -66,6 +66,7 @@ from The Open Group.
#endif #endif
#include "Xlibint.h" #include "Xlibint.h"
#include "Xlcint.h" #include "Xlcint.h"
#include "reallocarray.h"
static int static int
_XIMNestedListToNestedList( _XIMNestedListToNestedList(
...@@ -128,7 +129,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return) ...@@ -128,7 +129,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
return; return;
} }
args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg)); args = Xmallocarray((unsigned)max_count + 1, sizeof(XIMArg));
*args_return = args; *args_return = args;
if (!args) return; if (!args) return;
......
...@@ -67,6 +67,7 @@ Sun Microsystems, Inc. or its licensors is granted. ...@@ -67,6 +67,7 @@ Sun Microsystems, Inc. or its licensors is granted.
#include "Xlibint.h" #include "Xlibint.h"
#include "Xlcint.h" #include "Xlcint.h"
#include "XlcGeneric.h" #include "XlcGeneric.h"
#include "reallocarray.h"
#ifndef MAXINT #ifndef MAXINT
#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1)) #define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1))
...@@ -266,7 +267,7 @@ _GetIMValues( ...@@ -266,7 +267,7 @@ _GetIMValues(
*(XIMStyles **)p->value = styles; *(XIMStyles **)p->value = styles;
styles->count_styles = 1; styles->count_styles = 1;
styles->supported_styles = styles->supported_styles =
Xmalloc(styles->count_styles * sizeof(XIMStyle)); Xmallocarray(styles->count_styles, sizeof(XIMStyle));
styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone); styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
} else { } else {
break; break;
......
...@@ -85,6 +85,7 @@ Sun Microsystems, Inc. or its licensors is granted. ...@@ -85,6 +85,7 @@ Sun Microsystems, Inc. or its licensors is granted.
#include "Xlibint.h" #include "Xlibint.h"
#include "XlcPublic.h" #include "XlcPublic.h"
#include "XlcPubI.h" #include "XlcPubI.h"
#include "reallocarray.h"
#define XI18N_DLREL 2 #define XI18N_DLREL 2
...@@ -185,7 +186,7 @@ resolve_object(char *path, const char *lc_name) ...@@ -185,7 +186,7 @@ resolve_object(char *path, const char *lc_name)
if (lc_len == 0) { /* True only for the 1st time */ if (lc_len == 0) { /* True only for the 1st time */
lc_len = OBJECT_INIT_LEN; 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; if (!xi18n_objects_list) return;
} }
snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS"); snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS");
...@@ -207,8 +208,9 @@ resolve_object(char *path, const char *lc_name) ...@@ -207,8 +208,9 @@ resolve_object(char *path, const char *lc_name)
if (lc_count == lc_len) { if (lc_count == lc_len) {
int new_len = lc_len + OBJECT_INC_LEN; int new_len = lc_len + OBJECT_INC_LEN;
XI18NObjectsListRec *tmp = Xrealloc(xi18n_objects_list, XI18NObjectsListRec *tmp =
sizeof(XI18NObjectsListRec) * new_len); Xreallocarray(xi18n_objects_list, new_len,
sizeof(XI18NObjectsListRec));
if (tmp == NULL) if (tmp == NULL)
goto done; goto done;
xi18n_objects_list = tmp; xi18n_objects_list = tmp;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <X11/Xresource.h> #include <X11/Xresource.h>
#include "Xlibint.h" #include "Xlibint.h"
#include "XlcPubI.h" #include "XlcPubI.h"
#include "reallocarray.h"
#else /* NOT_X_ENV */ #else /* NOT_X_ENV */
...@@ -492,7 +493,7 @@ append_value_list (void) ...@@ -492,7 +493,7 @@ append_value_list (void)
char **prev_list = value_list; char **prev_list = value_list;
value_list = (char **) value_list = (char **)
Xrealloc(value_list, sizeof(char *) * (value_num + 2)); Xreallocarray(value_list, value_num + 2, sizeof(char *));
if (value_list == NULL) { if (value_list == NULL) {
Xfree(prev_list); Xfree(prev_list);
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <stdio.h> #include <stdio.h>
#include "Xlibint.h" #include "Xlibint.h"
#include "XlcGeneric.h" #include "XlcGeneric.h"
#include "reallocarray.h"
static XLCd create (const char *name, XLCdMethods methods); static XLCd create (const char *name, XLCdMethods methods);
static Bool initialize (XLCd lcd); static Bool initialize (XLCd lcd);
...@@ -157,8 +158,8 @@ add_charset( ...@@ -157,8 +158,8 @@ add_charset(
int num; int num;
if ((num = codeset->num_charsets)) if ((num = codeset->num_charsets))
new_list = Xrealloc(codeset->charset_list, new_list = Xreallocarray(codeset->charset_list,
(num + 1) * sizeof(XlcCharSet)); num + 1, sizeof(XlcCharSet));
else else
new_list = Xmalloc(sizeof(XlcCharSet)); new_list = Xmalloc(sizeof(XlcCharSet));
...@@ -184,8 +185,8 @@ add_codeset( ...@@ -184,8 +185,8 @@ add_codeset(
return NULL; return NULL;
if ((num = gen->codeset_num)) if ((num = gen->codeset_num))
new_list = Xrealloc(gen->codeset_list, new_list = Xreallocarray(gen->codeset_list,
(num + 1) * sizeof(CodeSet)); num + 1, sizeof(CodeSet));
else else
new_list = Xmalloc(sizeof(CodeSet)); new_list = Xmalloc(sizeof(CodeSet));
...@@ -231,8 +232,8 @@ add_parse_list( ...@@ -231,8 +232,8 @@ add_parse_list(
} }
if ((num = gen->mb_parse_list_num)) if ((num = gen->mb_parse_list_num))
new_list = Xrealloc(gen->mb_parse_list, new_list = Xreallocarray(gen->mb_parse_list,
(num + 2) * sizeof(ParseInfo)); num + 2, sizeof(ParseInfo));
else { else {
new_list = Xmalloc(2 * sizeof(ParseInfo)); new_list = Xmalloc(2 * sizeof(ParseInfo));
} }
...@@ -350,7 +351,7 @@ _XlcParse_scopemaps( ...@@ -350,7 +351,7 @@ _XlcParse_scopemaps(
const char *str_sc; const char *str_sc;
num = count_scopemap(str); num = count_scopemap(str);
scope = Xmalloc(num * sizeof(FontScopeRec)); scope = Xmallocarray(num, sizeof(FontScopeRec));
if (scope == NULL) if (scope == NULL)
return NULL; return NULL;
...@@ -535,8 +536,8 @@ add_conversion( ...@@ -535,8 +536,8 @@ add_conversion(
int num; int num;
if ((num = gen->segment_conv_num) > 0) { if ((num = gen->segment_conv_num) > 0) {
new_list = Xrealloc(gen->segment_conv, new_list = Xreallocarray(gen->segment_conv,
(num + 1) * sizeof(SegConvRec)); num + 1, sizeof(SegConvRec));
} else { } else {
new_list = Xmalloc(sizeof(SegConvRec)); new_list = Xmalloc(sizeof(SegConvRec));
} }
...@@ -667,7 +668,7 @@ create_ctextseg( ...@@ -667,7 +668,7 @@ create_ctextseg(
ret->side = XlcGLGR; ret->side = XlcGLGR;
strcpy(cset_name,ret->name); strcpy(cset_name,ret->name);
} }
ret->area = Xmalloc((num - 1)*sizeof(FontScopeRec)); ret->area = Xmallocarray(num - 1, sizeof(FontScopeRec));
if (ret->area == NULL) { if (ret->area == NULL) {
Xfree (cset_name); Xfree (cset_name);
Xfree (ret->name); Xfree (ret->name);
...@@ -870,8 +871,8 @@ load_generic( ...@@ -870,8 +871,8 @@ load_generic(
codeset->byteM = NULL; codeset->byteM = NULL;
break ; break ;
} }
codeset->byteM = Xmalloc( codeset->byteM = Xmallocarray(codeset->length,
(codeset->length)*sizeof(ByteInfoListRec)); sizeof(ByteInfoListRec));
if (codeset->byteM == NULL) { if (codeset->byteM == NULL) {
goto err; goto err;
} }
...@@ -882,7 +883,7 @@ load_generic( ...@@ -882,7 +883,7 @@ load_generic(
(codeset->byteM)[M-1].M = M; (codeset->byteM)[M-1].M = M;
(codeset->byteM)[M-1].byteinfo_num = num; (codeset->byteM)[M-1].byteinfo_num = num;
(codeset->byteM)[M-1].byteinfo = (codeset->byteM)[M-1].byteinfo =
Xmalloc(num * sizeof(ByteInfoRec)); Xmallocarray(num, sizeof(ByteInfoRec));
for (ii = 0 ; ii < num ; ii++) { for (ii = 0 ; ii < num ; ii++) {
tmpb = (codeset->byteM)[M-1].byteinfo ; tmpb = (codeset->byteM)[M-1].byteinfo ;
/* default 0x00 - 0xff */ /* default 0x00 - 0xff */
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "XlcPubI.h" #include "XlcPubI.h"
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include "reallocarray.h"
static XPointer * static XPointer *
alloc_list( alloc_list(
...@@ -40,11 +41,11 @@ alloc_list( ...@@ -40,11 +41,11 @@ alloc_list(
if (is_wide_char) { if (is_wide_char) {
wchar_t **wstr_list; wchar_t **wstr_list;
wstr_list = Xmalloc(count * sizeof(wchar_t *)); wstr_list = Xmallocarray(count, sizeof(wchar_t *));
if (wstr_list == NULL) if (wstr_list == NULL)
return (XPointer *) NULL; return (XPointer *) NULL;
*wstr_list = Xmalloc(nitems * sizeof(wchar_t)); *wstr_list = Xmallocarray(nitems, sizeof(wchar_t));
if (*wstr_list == NULL) { if (*wstr_list == NULL) {
Xfree(wstr_list); Xfree(wstr_list);
return (XPointer *) NULL; return (XPointer *) NULL;
...@@ -54,7 +55,7 @@ alloc_list( ...@@ -54,7 +55,7 @@ alloc_list(
} else { } else {
char **str_list; char **str_list;
str_list = Xmalloc(count * sizeof(char *)); str_list = Xmallocarray(count, sizeof(char *));
if (str_list == NULL) if (str_list == NULL)
return (XPointer *) NULL; return (XPointer *) NULL;
......
...@@ -66,6 +66,7 @@ from The Open Group. ...@@ -66,6 +66,7 @@ from The Open Group.
#endif #endif
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "XlcPubI.h" #include "XlcPubI.h"
#include "reallocarray.h"
#ifdef XTHREADS #ifdef XTHREADS
LockInfoPtr _Xi18n_lock; LockInfoPtr _Xi18n_lock;
...@@ -564,7 +565,7 @@ _XlcVaToArgList( ...@@ -564,7 +565,7 @@ _XlcVaToArgList(
{ {
XlcArgList args; XlcArgList args;
*args_ret = args = Xmalloc(sizeof(XlcArg) * count); *args_ret = args = Xmallocarray(count, sizeof(XlcArg));
if (args == (XlcArgList) NULL) if (args == (XlcArgList) NULL)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment