diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-04-12 21:27:45 -0700 |
---|---|---|
committer | Ulrich Sibiller <uli42@gmx.de> | 2016-10-19 21:40:25 +0200 |
commit | 7d7224d8543e85e3a34a1cddf99f3eac9aa9050b (patch) | |
tree | 15e7affd8446b031fe6bc98bcb5b0419dc04ab7b /nx-X11/lib/X11 | |
parent | 369c956683108226a30bbdd55355f0d8ae57eeb4 (diff) | |
download | nx-libs-7d7224d8543e85e3a34a1cddf99f3eac9aa9050b.tar.gz nx-libs-7d7224d8543e85e3a34a1cddf99f3eac9aa9050b.tar.bz2 nx-libs-7d7224d8543e85e3a34a1cddf99f3eac9aa9050b.zip |
Replace Xmalloc+bzero pairs with Xcalloc calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Backported-to-NX-by: Ulrich Sibiller <uli42@gmx.de>
Diffstat (limited to 'nx-X11/lib/X11')
-rw-r--r-- | nx-X11/lib/X11/Quarks.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/XDefaultOMIF.c | 16 | ||||
-rw-r--r-- | nx-X11/lib/X11/Xrm.c | 6 | ||||
-rw-r--r-- | nx-X11/lib/X11/imDefIc.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/imInt.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/imLcIc.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/imRm.c | 18 | ||||
-rw-r--r-- | nx-X11/lib/X11/imRmAttr.c | 15 | ||||
-rw-r--r-- | nx-X11/lib/X11/imThaiIc.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/imTrX.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/imTrans.c | 4 | ||||
-rw-r--r-- | nx-X11/lib/X11/lcCharSet.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/lcDB.c | 6 | ||||
-rw-r--r-- | nx-X11/lib/X11/lcGenConv.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/lcGeneric.c | 15 | ||||
-rw-r--r-- | nx-X11/lib/X11/lcJis.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/X11/lcPublic.c | 6 | ||||
-rw-r--r-- | nx-X11/lib/X11/omGeneric.c | 9 |
18 files changed, 39 insertions, 83 deletions
diff --git a/nx-X11/lib/X11/Quarks.c b/nx-X11/lib/X11/Quarks.c index 9a7cb04d5..1bba6da4d 100644 --- a/nx-X11/lib/X11/Quarks.c +++ b/nx-X11/lib/X11/Quarks.c @@ -206,10 +206,9 @@ ExpandQuarkTable(void) #endif newmask = 0x1ff; } - entries = (Entry *)Xmalloc(sizeof(Entry) * (newmask + 1)); + entries = Xcalloc(newmask + 1, sizeof(Entry)); if (!entries) return False; - bzero((char *)entries, sizeof(Entry) * (newmask + 1)); quarkTable = entries; quarkMask = newmask; quarkRehash = quarkMask - 2; diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 6975aa806..b74683aa7 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -128,10 +128,9 @@ init_fontset( data = XOM_GENERIC(oc->core.om)->data; - font_set = (FontSet) Xmalloc(sizeof(FontSetRec)); + font_set = Xcalloc(1, sizeof(FontSetRec)); if (font_set == NULL) return False; - bzero((char *) font_set, sizeof(FontSetRec)); gen = XOC_GENERIC(oc); gen->font_set = font_set; @@ -1005,10 +1004,9 @@ create_oc( { XOC oc; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1126,15 +1124,13 @@ add_data( XOMGenericPart *gen = XOM_GENERIC(om); OMData new; - new = (OMData) Xmalloc(sizeof(OMDataRec)); + new = Xcalloc(1, sizeof(OMDataRec)); if (new == NULL) return NULL; gen->data = new; - bzero((char *) new, sizeof(OMDataRec)); - return new; } @@ -1168,10 +1164,9 @@ init_om( if (data == NULL) return False; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return False; - bzero((char *) font_data, sizeof(FontDataRec) * count); data->font_data = font_data; data->font_data_count = count; @@ -1237,10 +1232,9 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = (XOMMethods)&methods; om->core.lcd = lcd; diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 81fbfaf35..d3668affa 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -581,23 +581,21 @@ static void GrowTable( ltable = (LTable)table; /* cons up a copy to make MoveValues look symmetric */ otable = *ltable; - ltable->buckets = (VEntry *)Xmalloc(i * sizeof(VEntry)); + ltable->buckets = Xcalloc(i, sizeof(VEntry)); if (!ltable->buckets) { ltable->buckets = otable.buckets; return; } ltable->table.mask = i - 1; - bzero((char *)ltable->buckets, i * sizeof(VEntry)); MoveValues(&otable, ltable); } else { register NTable ntable; - ntable = (NTable)Xmalloc(sizeof(NTableRec) + i * sizeof(NTable)); + ntable = Xcalloc(1, sizeof(NTableRec) + (i * sizeof(NTable))); if (!ntable) return; *ntable = *table; ntable->mask = i - 1; - bzero((char *)NodeBuckets(ntable), i * sizeof(NTable)); *prev = ntable; MoveTables(table, ntable); } diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index ba720b56c..85029ad1f 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -1425,10 +1425,9 @@ _XimProtoCreateIC( if (!(_XimGetInputStyle(arg, &input_style))) return (XIC)NULL; - if ((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) + if ((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) return (XIC)NULL; - bzero((char *)ic, sizeof(XicRec)); ic->methods = &ic_methods; ic->core.im = (XIM)im; ic->core.input_style = input_style; diff --git a/nx-X11/lib/X11/imInt.c b/nx-X11/lib/X11/imInt.c index c78ffc68d..bab4b5399 100644 --- a/nx-X11/lib/X11/imInt.c +++ b/nx-X11/lib/X11/imInt.c @@ -204,9 +204,8 @@ _XimOpenIM( Xim im; register int i; - if (!(im = (Xim)Xmalloc(sizeof(XimRec)))) + if (!(im = Xcalloc(1, sizeof(XimRec)))) return (XIM)NULL; - bzero(im, sizeof(XimRec)); im->core.lcd = lcd; im->core.ic_chain = (XIC)NULL; diff --git a/nx-X11/lib/X11/imLcIc.c b/nx-X11/lib/X11/imLcIc.c index 66ff3e913..4a452269a 100644 --- a/nx-X11/lib/X11/imLcIc.c +++ b/nx-X11/lib/X11/imLcIc.c @@ -143,10 +143,9 @@ _XimLocalCreateIC( unsigned int num; int len; - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { + if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); } - bzero((char *)ic, sizeof(XicRec)); ic->methods = &Local_ic_methods; ic->core.im = im; diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index 7f79765e1..448cf41e6 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -360,10 +360,9 @@ _XimDefaultStyles( n = XIMNumber(supported_local_styles) - 1; len = sizeof(XIMStyles) + sizeof(XIMStyle) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); styles = (XIMStyles *)tmp; if (n > 0) { @@ -396,10 +395,9 @@ _XimDefaultIMValues( n = XIMNumber(supported_local_im_values_list); len = sizeof(XIMValuesList) + sizeof(char **) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); values_list = (XIMValuesList *)tmp; if (n > 0) { @@ -433,10 +431,9 @@ _XimDefaultICValues( n = XIMNumber(supported_local_ic_values_list); len = sizeof(XIMValuesList) + sizeof(char **) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); values_list = (XIMValuesList *)tmp; if (n > 0) { @@ -1085,10 +1082,9 @@ _XimDecodeStyles( num = styles->count_styles; len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); out = (XIMStyles *)tmp; if(num >0) { @@ -1124,10 +1120,9 @@ _XimDecodeValues( num = values_list->count_values; len = sizeof(XIMValuesList) + sizeof(char **) * num; - if(!(tmp = (char *)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); out = (XIMValuesList *)tmp; if(num) { @@ -2143,10 +2138,9 @@ _XimSetResourceList( XIMResourceList res; len = sizeof(XIMResource) * num_resource; - if(!(res = (XIMResourceList)Xmalloc(len))) { + if(!(res = Xcalloc(1, len))) { return False; } - bzero((char *)res, len); for(i = 0; i < num_resource; i++, id++) { res[i] = resource[i]; diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index 975a1edcd..56a55a13f 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -1405,7 +1405,6 @@ _XimGetAttributeID( { unsigned int n; XIMResourceList res; - int res_len; char *names; int names_len; XPointer tmp; @@ -1423,18 +1422,15 @@ _XimGetAttributeID( if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len))) return False; - res_len = sizeof(XIMResource) * n; - if (!(res = (XIMResourceList)Xmalloc(res_len))) + if (!(res = Xcalloc(n, sizeof(XIMResource)))) return False; - bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) { + if (!(tmp = Xcalloc(1, values_len))) { Xfree(res); return False; } - bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; values = (char **)((char *)tmp + sizeof(XIMValuesList)); @@ -1472,18 +1468,15 @@ _XimGetAttributeID( if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len))) return False; - res_len = sizeof(XIMResource) * n; - if (!(res = (XIMResourceList)Xmalloc(res_len))) + if (!(res = Xcalloc(n, sizeof(XIMResource)))) return False; - bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) { + if (!(tmp = Xcalloc(1, values_len))) { Xfree(res); return False; } - bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; values = (char **)((char *)tmp + sizeof(XIMValuesList)); diff --git a/nx-X11/lib/X11/imThaiIc.c b/nx-X11/lib/X11/imThaiIc.c index 72e99ba75..ded78e38f 100644 --- a/nx-X11/lib/X11/imThaiIc.c +++ b/nx-X11/lib/X11/imThaiIc.c @@ -157,10 +157,9 @@ _XimThaiCreateIC( int len; DefTree *tree; - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { + if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); } - bzero((char *)ic, sizeof(XicRec)); ic->methods = &Thai_ic_methods; ic->core.im = im; diff --git a/nx-X11/lib/X11/imTrX.c b/nx-X11/lib/X11/imTrX.c index 2b5455f1b..6b757cee5 100644 --- a/nx-X11/lib/X11/imTrX.c +++ b/nx-X11/lib/X11/imTrX.c @@ -487,9 +487,8 @@ _XimXConf(Xim im, char *address) { XSpecRec *spec; - if (!(spec = (XSpecRec *)Xmalloc(sizeof(XSpecRec)))) + if (!(spec = Xcalloc(1, sizeof(XSpecRec)))) return False; - bzero(spec, sizeof(XSpecRec)); spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False); spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False); diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index 0fdc8cd9a..a974c0ca3 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -293,13 +293,11 @@ _XimTransConf( if (!(paddr = (char *)Xmalloc(strlen(address) + 1))) return False; - if (!(spec = (TransSpecRec *) Xmalloc(sizeof(TransSpecRec)))) { + if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) { Xfree(paddr); return False; } - bzero(spec, sizeof(TransSpecRec)); - (void)strcpy(paddr, address); spec->address = paddr; diff --git a/nx-X11/lib/X11/lcCharSet.c b/nx-X11/lib/X11/lcCharSet.c index 0fa39d869..5d287811c 100644 --- a/nx-X11/lib/X11/lcCharSet.c +++ b/nx-X11/lib/X11/lcCharSet.c @@ -176,10 +176,9 @@ _XlcCreateDefaultCharSet( const char *colon; char *tmp; - charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec)); + charset = Xcalloc(1, sizeof(XlcCharSetRec)); if (charset == NULL) return (XlcCharSet) NULL; - bzero((char *) charset, sizeof(XlcCharSetRec)); name_len = strlen(name); ct_sequence_len = strlen(ct_sequence); diff --git a/nx-X11/lib/X11/lcDB.c b/nx-X11/lib/X11/lcDB.c index 1353acfe3..c11a79a6b 100644 --- a/nx-X11/lib/X11/lcDB.c +++ b/nx-X11/lib/X11/lcDB.c @@ -591,11 +591,10 @@ store_to_database( goto err; } - new = (Database)Xmalloc(sizeof(DatabaseRec)); + new = Xcalloc(1, sizeof(DatabaseRec)); if (new == (Database)NULL) { goto err; } - bzero(new, sizeof(DatabaseRec)); new->category = (char *)Xmalloc(strlen(parse_info.category) + 1); if (new->category == NULL) { @@ -1309,10 +1308,9 @@ _XlcCreateLocaleDataBase( return (XPointer)NULL; } n = CountDatabase(database); - lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1)); + lc_db = Xcalloc(n + 1, sizeof(XlcDatabaseRec)); if (lc_db == (XlcDatabase)NULL) goto err; - bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1)); for (p = database, i = 0; p && i < n; p = p->next, ++i) { lc_db[i].category_q = XrmStringToQuark(p->category); lc_db[i].name_q = XrmStringToQuark(p->name); diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 074a8d726..d5f5a9083 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -2660,10 +2660,9 @@ create_conv( *conv->methods = *methods; conv->methods->reset = init_state; - conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + conv->state = Xcalloc(1, sizeof(StateRec)); if (conv->state == NULL) goto err; - bzero((char *) conv->state, sizeof(StateRec)); state = (State) conv->state; state->lcd = lcd; diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index 688a4cfc4..df392e9af 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -60,15 +60,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec)); + lcd->core = Xcalloc(1, sizeof(XLCdGenericRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdGenericRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) @@ -180,10 +178,9 @@ add_codeset( CodeSet new, *new_list; int num; - new = (CodeSet) Xmalloc(sizeof(CodeSetRec)); + new = Xcalloc(1, sizeof(CodeSetRec)); if (new == NULL) return NULL; - bzero((char *) new, sizeof(CodeSetRec)); if ((num = gen->codeset_num)) new_list = (CodeSet *) Xrealloc(gen->codeset_list, @@ -223,16 +220,14 @@ add_parse_list( return False; strcpy(str, encoding); - new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec)); + new = Xcalloc(1, sizeof(ParseInfoRec)); if (new == NULL) goto err; - bzero((char *) new, sizeof(ParseInfoRec)); if (gen->mb_parse_table == NULL) { - gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */ + gen->mb_parse_table = Xcalloc(1, 256); /* 2^8 */ if (gen->mb_parse_table == NULL) goto err; - bzero((char *) gen->mb_parse_table, 256); } if ((num = gen->mb_parse_list_num)) diff --git a/nx-X11/lib/X11/lcJis.c b/nx-X11/lib/X11/lcJis.c index 594e6363c..551862d9b 100644 --- a/nx-X11/lib/X11/lcJis.c +++ b/nx-X11/lib/X11/lcJis.c @@ -545,10 +545,9 @@ create_conv( if (XLC_PUBLIC(lcd, is_state_depend)) conv->methods->reset = init_state; - conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + conv->state = Xcalloc(1, sizeof(StateRec)); if (conv->state == NULL) goto err; - bzero((char *) conv->state, sizeof(StateRec)); state = (State) conv->state; state->lcd = lcd; diff --git a/nx-X11/lib/X11/lcPublic.c b/nx-X11/lib/X11/lcPublic.c index 2c02f5fba..43b9286e7 100644 --- a/nx-X11/lib/X11/lcPublic.c +++ b/nx-X11/lib/X11/lcPublic.c @@ -80,15 +80,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec)); + lcd->core = Xcalloc(1, sizeof(XLCdPublicRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdPublicRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 32a066a75..fd8742436 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -1656,10 +1656,9 @@ create_oc( XOCMethodsList methods_list = oc_methods_list; int count; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1844,10 +1843,9 @@ create_om( { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = &methods; om->core.lcd = lcd; @@ -1915,10 +1913,9 @@ read_EncodingInfo( FontData font_data,ret; char *buf, *bufptr,*scp; int len; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return NULL; - bzero((char *) font_data, sizeof(FontDataRec) * count); ret = font_data; for ( ; count-- > 0; font_data++) { |