aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/X11/lcGeneric.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/lib/X11/lcGeneric.c')
-rw-r--r--nx-X11/lib/X11/lcGeneric.c134
1 files changed, 61 insertions, 73 deletions
diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c
index 69ea97db8..1c78a95c6 100644
--- a/nx-X11/lib/X11/lcGeneric.c
+++ b/nx-X11/lib/X11/lcGeneric.c
@@ -60,17 +60,15 @@ 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));
+ new = Xmalloc(sizeof(XLCdPublicMethodsRec));
if (new == NULL)
goto err;
memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
@@ -158,10 +156,10 @@ add_charset(
int num;
if ((num = codeset->num_charsets))
- new_list = (XlcCharSet *) Xrealloc(codeset->charset_list,
+ new_list = Xrealloc(codeset->charset_list,
(num + 1) * sizeof(XlcCharSet));
else
- new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet));
+ new_list = Xmalloc(sizeof(XlcCharSet));
if (new_list == NULL)
return False;
@@ -180,16 +178,15 @@ 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,
+ new_list = Xrealloc(gen->codeset_list,
(num + 1) * sizeof(CodeSet));
else
- new_list = (CodeSet *) Xmalloc(sizeof(CodeSet));
+ new_list = Xmalloc(sizeof(CodeSet));
if (new_list == NULL)
goto err;
@@ -218,28 +215,25 @@ add_parse_list(
unsigned char ch;
int num;
- str = (char *) Xmalloc(strlen(encoding) + 1);
+ str = strdup(encoding);
if (str == NULL)
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))
- new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list,
+ new_list = Xrealloc(gen->mb_parse_list,
(num + 2) * sizeof(ParseInfo));
else {
- new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo));
+ new_list = Xmalloc(2 * sizeof(ParseInfo));
}
if (new_list == NULL)
@@ -265,8 +259,8 @@ add_parse_list(
err:
Xfree(str);
- if (new)
- Xfree(new);
+
+ Xfree(new);
return False;
}
@@ -279,12 +273,10 @@ free_charset(
ParseInfo *parse_info;
int num;
- if (gen->mb_parse_table)
- Xfree(gen->mb_parse_table);
+ Xfree(gen->mb_parse_table);
if ((num = gen->mb_parse_list_num) > 0) {
for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
- if ((*parse_info)->encoding)
- Xfree((*parse_info)->encoding);
+ Xfree((*parse_info)->encoding);
Xfree(*parse_info);
}
Xfree(gen->mb_parse_list);
@@ -357,7 +349,7 @@ _XlcParse_scopemaps(
const char *str_sc;
num = count_scopemap(str);
- scope = (FontScope) Xmalloc(num * sizeof(FontScopeRec));
+ scope = Xmalloc(num * sizeof(FontScopeRec));
if (scope == NULL)
return NULL;
@@ -428,23 +420,23 @@ read_charset_define(
char name[BUFSIZ];
XlcCharSet charsetd;
char **value;
- int num, new;
+ int num, new = 0;
XlcSide side = XlcUnknown;
char *tmp;
for (i=0; ; i++) { /* loop start */
charsetd = 0;
- sprintf(csd, "csd%d", i);
+ snprintf(csd, sizeof(csd), "csd%d", i);
/* charset_name */
- sprintf(name, "%s.%s", csd, "charset_name");
+ snprintf(name, sizeof(name), "%s.%s", csd, "charset_name");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
_XlcDbg_printValue(name,value,num);
if (num > 0) {
/* hackers will get truncated -- C'est la vie */
strncpy(cset_name,value[0], sizeof cset_name - 1);
cset_name[(sizeof cset_name) - 1] = '\0';
- sprintf(name, "%s.%s", csd , "side");
+ snprintf(name, sizeof(name), "%s.%s", csd , "side");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -468,30 +460,29 @@ read_charset_define(
break;
}
if (new) {
- tmp = (char *)Xmalloc(strlen(cset_name)+1);
+ tmp = strdup(cset_name);
if (tmp == NULL)
return;
- strcpy(tmp,cset_name);
charsetd->name = tmp;
}
/* side */
charsetd->side = side ;
/* length */
- sprintf(name, "%s.%s", csd, "length");
+ snprintf(name, sizeof(name), "%s.%s", csd, "length");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
charsetd->char_size = atoi(value[0]);
}
/* gc_number */
- sprintf(name, "%s.%s", csd, "gc_number");
+ snprintf(name, sizeof(name), "%s.%s", csd, "gc_number");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
charsetd->set_size = atoi(value[0]);
}
/* string_encoding */
- sprintf(name, "%s.%s", csd, "string_encoding");
+ snprintf(name, sizeof(name), "%s.%s", csd, "string_encoding");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -502,7 +493,7 @@ read_charset_define(
}
}
/* sequence */
- sprintf(name, "%s.%s", csd, "sequence");
+ snprintf(name, sizeof(name), "%s.%s", csd, "sequence");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -511,14 +502,14 @@ read_charset_define(
Xfree(charsetd->ct_sequence);
}
*/
- tmp = (char *)Xmalloc(strlen(value[0])+1);
+ tmp = Xmalloc(strlen(value[0])+1);
if (tmp == NULL)
return;
charsetd->ct_sequence = tmp;
string_to_encoding(value[0],tmp);
}
/* encoding_name */
- sprintf(name, "%s.%s", csd, "encoding_name");
+ snprintf(name, sizeof(name), "%s.%s", csd, "encoding_name");
_XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -527,8 +518,7 @@ read_charset_define(
Xfree(charsetd->encoding_name);
}
*/
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- strcpy(tmp,value[0]);
+ tmp = strdup(value[0]);
charsetd->encoding_name = tmp;
charsetd->xrm_encoding_name = XrmStringToQuark(tmp);
}
@@ -544,10 +534,10 @@ add_conversion(
int num;
if ((num = gen->segment_conv_num) > 0) {
- new_list = (SegConv) Xrealloc(gen->segment_conv,
+ new_list = Xrealloc(gen->segment_conv,
(num + 1) * sizeof(SegConvRec));
} else {
- new_list = (SegConv) Xmalloc(sizeof(SegConvRec));
+ new_list = Xmalloc(sizeof(SegConvRec));
}
if (new_list == NULL)
@@ -573,10 +563,10 @@ read_segmentconversion(
SegConv conversion;
for (i=0 ; ; i++) { /* loop start */
conversion = 0;
- sprintf(conv, "conv%d", i);
+ snprintf(conv, sizeof(conv), "conv%d", i);
/* length */
- sprintf(name, "%s.%s", conv, "length");
+ snprintf(name, sizeof(name), "%s.%s", conv, "length");
_XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
if (num > 0) {
if (conversion == NULL &&
@@ -593,33 +583,31 @@ read_segmentconversion(
conversion->length = atoi(value[0]);
/* source_encoding */
- sprintf(name, "%s.%s", conv, "source_encoding");
+ snprintf(name, sizeof(name), "%s.%s", conv, "source_encoding");
_XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
if (num > 0) {
char *tmp;
_XlcDbg_printValue(name,value,num);
- tmp = (char *)Xmalloc(strlen(value[0])+1);
+ tmp = strdup(value[0]);
if (tmp == NULL)
return;
- strcpy(tmp,value[0]);
conversion->source_encoding = tmp;
conversion->source = srch_charset_define(tmp,&new);
}
/* destination_encoding */
- sprintf(name, "%s.%s", conv, "destination_encoding");
+ snprintf(name, sizeof(name), "%s.%s", conv, "destination_encoding");
_XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
if (num > 0) {
char *tmp;
_XlcDbg_printValue(name,value,num);
- tmp = (char *)Xmalloc(strlen(value[0])+1);
+ tmp = strdup(value[0]);
if (tmp == NULL)
return;
- strcpy(tmp,value[0]);
conversion->destination_encoding = tmp;
conversion->dest = srch_charset_define(tmp,&new);
}
/* range */
- sprintf(name, "%s.%s", conv, "range");
+ snprintf(name, sizeof(name), "%s.%s", conv, "range");
_XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -627,7 +615,7 @@ read_segmentconversion(
&(conversion->range.start), &(conversion->range.end));
}
/* conversion */
- sprintf(name, "%s.%s", conv, "conversion");
+ snprintf(name, sizeof(name), "%s.%s", conv, "conversion");
_XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -645,18 +633,19 @@ create_ctextseg(
ExtdSegment ret;
char* ptr;
char* cset_name = NULL;
+ size_t cset_len;
int i,new;
FontScope scope;
- ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
+ ret = Xmalloc(sizeof(ExtdSegmentRec));
if (ret == NULL)
return NULL;
- ret->name = (char *)Xmalloc(strlen(value[0]) + 1);
+ ret->name = strdup(value[0]);
if (ret->name == NULL) {
Xfree (ret);
return NULL;
}
- strcpy(ret->name,value[0]);
- cset_name = (char*) Xmalloc (strlen(ret->name) + 1);
+ cset_len = strlen(ret->name) + 1;
+ cset_name = Xmalloc (cset_len);
if (cset_name == NULL) {
Xfree (ret->name);
Xfree (ret);
@@ -668,16 +657,16 @@ create_ctextseg(
ptr++;
if (!_XlcNCompareISOLatin1(ptr, "GL", 2)) {
ret->side = XlcGL;
- sprintf(cset_name,"%s:%s",ret->name,"GL");
+ snprintf(cset_name, cset_len, "%s:%s", ret->name, "GL");
} else {
ret->side = XlcGR;
- sprintf(cset_name,"%s:%s",ret->name,"GR");
+ snprintf(cset_name, cset_len, "%s:%s", ret->name, "GR");
}
} else {
ret->side = XlcGLGR;
strcpy(cset_name,ret->name);
}
- ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec));
+ ret->area = Xmalloc((num - 1)*sizeof(FontScopeRec));
if (ret->area == NULL) {
Xfree (cset_name);
Xfree (ret->name);
@@ -742,10 +731,10 @@ load_generic(
char cs[16];
char name[BUFSIZ];
- sprintf(cs, "cs%d", i);
+ snprintf(cs, sizeof(cs), "cs%d", i);
/***** codeset.side *****/
- sprintf(name, "%s.%s", cs , "side");
+ snprintf(name, sizeof(name), "%s.%s", cs , "side");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
char *tmp;
@@ -772,7 +761,7 @@ load_generic(
}
/***** codeset.length *****/
- sprintf(name, "%s.%s", cs , "length");
+ snprintf(name, sizeof(name), "%s.%s", cs , "length");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
@@ -783,7 +772,7 @@ load_generic(
}
/***** codeset.mb_encoding *****/
- sprintf(name, "%s.%s", cs, "mb_encoding");
+ snprintf(name, sizeof(name), "%s.%s", cs, "mb_encoding");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
static struct {
@@ -819,7 +808,7 @@ load_generic(
}
/***** codeset.wc_encoding *****/
- sprintf(name, "%s.%s", cs, "wc_encoding");
+ snprintf(name, sizeof(name), "%s.%s", cs, "wc_encoding");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
@@ -830,7 +819,7 @@ load_generic(
}
/***** codeset.ct_encoding *****/
- sprintf(name, "%s.%s", cs, "ct_encoding");
+ snprintf(name, sizeof(name), "%s.%s", cs, "ct_encoding");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
char *encoding;
@@ -872,7 +861,7 @@ load_generic(
unsigned long start,end;
ByteInfo tmpb;
- sprintf(name,"%s.%s%d",cs,"byte",M);
+ snprintf(name, sizeof(name),"%s.%s%d",cs,"byte",M);
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (M == 1) {
@@ -880,8 +869,7 @@ load_generic(
codeset->byteM = NULL;
break ;
}
- codeset->byteM =
- (ByteInfoListRec *)Xmalloc(
+ codeset->byteM = Xmalloc(
(codeset->length)*sizeof(ByteInfoListRec));
if (codeset->byteM == NULL) {
goto err;
@@ -893,7 +881,7 @@ load_generic(
(codeset->byteM)[M-1].M = M;
(codeset->byteM)[M-1].byteinfo_num = num;
(codeset->byteM)[M-1].byteinfo =
- (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec));
+ Xmalloc(num * sizeof(ByteInfoRec));
for (ii = 0 ; ii < num ; ii++) {
tmpb = (codeset->byteM)[M-1].byteinfo ;
/* default 0x00 - 0xff */
@@ -907,7 +895,7 @@ load_generic(
/***** codeset.mb_conversion *****/
- sprintf(name, "%s.%s", cs, "mb_conversion");
+ snprintf(name, sizeof(name), "%s.%s", cs, "mb_conversion");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -919,7 +907,7 @@ load_generic(
/* [\x%x,\x%x]->\x%x,... */
}
/***** codeset.ct_conversion *****/
- sprintf(name, "%s.%s", cs, "ct_conversion");
+ snprintf(name, sizeof(name), "%s.%s", cs, "ct_conversion");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
@@ -931,14 +919,14 @@ load_generic(
/* [\x%x,\x%x]->\x%x,... */
}
/***** codeset.ct_conversion_file *****/
- sprintf(name, "%s.%s", cs, "ct_conversion_file");
+ snprintf(name, sizeof(name), "%s.%s", cs, "ct_conversion_file");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);
/* [\x%x,\x%x]->\x%x,... */
}
/***** codeset.ct_extended_segment *****/
- sprintf(name, "%s.%s", cs, "ct_extended_segment");
+ snprintf(name, sizeof(name), "%s.%s", cs, "ct_extended_segment");
_XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
if (num > 0) {
_XlcDbg_printValue(name,value,num);