aboutsummaryrefslogtreecommitdiff
path: root/libX11/src/xlibi18n
diff options
context:
space:
mode:
Diffstat (limited to 'libX11/src/xlibi18n')
-rw-r--r--libX11/src/xlibi18n/ICWrap.c14
-rw-r--r--libX11/src/xlibi18n/IMWrap.c2
-rw-r--r--libX11/src/xlibi18n/XDefaultIMIF.c12
-rw-r--r--libX11/src/xlibi18n/XDefaultOMIF.c33
-rw-r--r--libX11/src/xlibi18n/XlcDL.c29
-rw-r--r--libX11/src/xlibi18n/XlcPubI.h4
-rw-r--r--libX11/src/xlibi18n/lcCT.c18
-rw-r--r--libX11/src/xlibi18n/lcCharSet.c10
-rw-r--r--libX11/src/xlibi18n/lcConv.c10
-rw-r--r--libX11/src/xlibi18n/lcDB.c29
-rw-r--r--libX11/src/xlibi18n/lcDynamic.c4
-rw-r--r--libX11/src/xlibi18n/lcFile.c146
-rw-r--r--libX11/src/xlibi18n/lcGeneric.c89
-rw-r--r--libX11/src/xlibi18n/lcPrTxt.c10
-rw-r--r--libX11/src/xlibi18n/lcPubWrap.c2
-rw-r--r--libX11/src/xlibi18n/lcPublic.c5
-rw-r--r--libX11/src/xlibi18n/lcRM.c10
-rw-r--r--libX11/src/xlibi18n/lcTxtPr.c4
-rw-r--r--libX11/src/xlibi18n/lcUTF8.c20
-rw-r--r--libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c6
-rw-r--r--libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c14
-rw-r--r--libX11/src/xlibi18n/lcWrap.c16
-rw-r--r--libX11/src/xlibi18n/mbWMProps.c4
-rw-r--r--libX11/src/xlibi18n/mbWrap.c12
-rw-r--r--libX11/src/xlibi18n/utf8WMProps.c4
-rw-r--r--libX11/src/xlibi18n/utf8Wrap.c12
26 files changed, 237 insertions, 282 deletions
diff --git a/libX11/src/xlibi18n/ICWrap.c b/libX11/src/xlibi18n/ICWrap.c
index 1eacfa5f1..2a1d0d670 100644
--- a/libX11/src/xlibi18n/ICWrap.c
+++ b/libX11/src/xlibi18n/ICWrap.c
@@ -128,7 +128,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
return;
}
- args = (XIMArg *)Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg));
+ args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg));
*args_return = args;
if (!args) return;
@@ -186,7 +186,7 @@ XSetIMValues(XIM im, ...)
va_end(var);
ret = (*im->methods->set_values) (im, args);
- if (args) Xfree((char *)args);
+ if (args) Xfree(args);
return ret;
}
@@ -213,7 +213,7 @@ XGetIMValues(XIM im, ...)
va_end(var);
ret = (*im->methods->get_values) (im, args);
- if (args) Xfree((char *)args);
+ if (args) Xfree(args);
return ret;
}
@@ -245,7 +245,7 @@ XCreateIC(XIM im, ...)
va_end(var);
ic = (XIC) (*im->methods->create_ic) (im, args);
- if (args) Xfree((char *)args);
+ if (args) Xfree(args);
if (ic) {
ic->core.next = im->core.ic_chain;
im->core.ic_chain = ic;
@@ -271,7 +271,7 @@ XDestroyIC(XIC ic)
}
}
}
- Xfree ((char *) ic);
+ Xfree (ic);
}
char *
@@ -300,7 +300,7 @@ XGetICValues(XIC ic, ...)
va_end(var);
ret = (*ic->methods->get_values) (ic, args);
- if (args) Xfree((char *)args);
+ if (args) Xfree(args);
return ret;
}
@@ -330,7 +330,7 @@ XSetICValues(XIC ic, ...)
va_end(var);
ret = (*ic->methods->set_values) (ic, args);
- if (args) Xfree((char *)args);
+ if (args) Xfree(args);
return ret;
}
diff --git a/libX11/src/xlibi18n/IMWrap.c b/libX11/src/xlibi18n/IMWrap.c
index 0f6ed5593..a7c1d98c1 100644
--- a/libX11/src/xlibi18n/IMWrap.c
+++ b/libX11/src/xlibi18n/IMWrap.c
@@ -134,7 +134,7 @@ XCloseIM(XIM im)
s = (im->methods->close) (im);
for (ic = im->core.ic_chain; ic; ic = ic->core.next)
ic->core.im = (XIM)NULL;
- Xfree ((char *) im);
+ Xfree (im);
_XCloseLC (lcd);
return (s);
}
diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c
index 36a457ea5..f271bded1 100644
--- a/libX11/src/xlibi18n/XDefaultIMIF.c
+++ b/libX11/src/xlibi18n/XDefaultIMIF.c
@@ -185,10 +185,10 @@ _XDefaultOpenIM(
return((XIM)NULL);
}
- if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
+ if ((im = Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
return((XIM)NULL);
}
- if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec)))
+ if ((local_impart = Xmalloc(sizeof(XIMStaticXIMRec)))
== (XIMStaticXIMRec *)NULL) {
Xfree(im);
return((XIM)NULL);
@@ -274,11 +274,11 @@ _GetIMValues(
for (p = values; p->name != NULL; p++) {
if (strcmp(p->name, XNQueryInputStyle) == 0) {
- styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles));
+ styles = Xmalloc(sizeof(XIMStyles));
*(XIMStyles **)p->value = styles;
styles->count_styles = 1;
styles->supported_styles =
- (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle));
+ Xmalloc(styles->count_styles * sizeof(XIMStyle));
styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
} else {
break;
@@ -345,7 +345,7 @@ _CreateIC(XIM im, XIMArg *arg)
{
XIC ic;
- if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
+ if ((ic = Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
return ((XIC)NULL);
}
memset(ic, 0, sizeof(XICRec));
@@ -453,7 +453,7 @@ _WcLookupString(
XComposeStatus NotSupportedYet ;
int length;
/* In single-byte, mb_len = wc_len */
- char *mb_buf = (char *)Xmalloc(wlen);
+ char *mb_buf = Xmalloc(wlen);
length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet);
diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c
index 953475d37..2ff6c414c 100644
--- a/libX11/src/xlibi18n/XDefaultOMIF.c
+++ b/libX11/src/xlibi18n/XDefaultOMIF.c
@@ -78,7 +78,7 @@ Sun Microsystems, Inc. or its licensors is granted.
#define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen)
#define DefineLocalBuf char local_buf[BUFSIZ]
-#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
+#define AllocLocalBuf(length) (length > BUFSIZ ? Xmalloc(length) : local_buf)
#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
typedef struct _FontDataRec {
@@ -334,15 +334,15 @@ init_core_part(
if (count == 0)
return False;
- font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *));
+ font_struct_list = Xmalloc(sizeof(XFontStruct *));
if (font_struct_list == NULL)
return False;
- font_name_list = (char **) Xmalloc(sizeof(char *));
+ font_name_list = Xmalloc(sizeof(char *));
if (font_name_list == NULL)
goto err;
- font_name_buf = (char *) Xmalloc(length);
+ font_name_buf = Xmalloc(length);
if (font_name_buf == NULL)
goto err;
@@ -580,11 +580,11 @@ set_missing_list(
if (count == 0)
return True;
- charset_list = (char **) Xmalloc(sizeof(char *));
+ charset_list = Xmalloc(sizeof(char *));
if (charset_list == NULL)
return False;
- charset_buf = (char *) Xmalloc(length);
+ charset_buf = Xmalloc(length);
if (charset_buf == NULL) {
Xfree(charset_list);
return False;
@@ -1150,10 +1150,9 @@ init_om(
FontData font_data;
char **required_list;
XOrientation *orientation;
- char **value, buf[BUFSIZ], *bufptr;
- int count, length = 0;
+ char *bufptr;
+ int i, count, length = 0;
- value = (char**)supported_charset_list;
count = XlcNumber(supported_charset_list);
data = add_data(om);
@@ -1166,14 +1165,8 @@ init_om(
data->font_data = font_data;
data->font_data_count = count;
- for ( ; count-- > 0; font_data++) {
-/*
-1266793
-This one is fine. *value points to one of the local strings in
-supported_charset_list[].
-*/
- strcpy(buf, *value++);
- font_data->name = strdup(buf);
+ for (i = 0; i < count; i++, font_data++) {
+ font_data->name = strdup(supported_charset_list[i]);
if (font_data->name == NULL)
return False;
}
@@ -1181,11 +1174,11 @@ supported_charset_list[].
length += strlen(data->font_data->name) + 1;
/* required charset list */
- required_list = (char **) Xmalloc(sizeof(char *));
+ required_list = Xmalloc(sizeof(char *));
if (required_list == NULL)
return False;
- bufptr = (char *) Xmalloc(length);
+ bufptr = Xmalloc(length);
if (bufptr == NULL) {
Xfree(required_list);
return False;
@@ -1201,7 +1194,7 @@ supported_charset_list[].
bufptr += strlen(bufptr) + 1;
/* orientation list */
- orientation = (XOrientation *) Xmalloc(sizeof(XOrientation));
+ orientation = Xmalloc(sizeof(XOrientation));
if (orientation == NULL)
return False;
diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c
index 75e193c05..a23603865 100644
--- a/libX11/src/xlibi18n/XlcDL.c
+++ b/libX11/src/xlibi18n/XlcDL.c
@@ -185,16 +185,10 @@ 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 = (XI18NObjectsList)
- Xmalloc(sizeof(XI18NObjectsListRec) * lc_len);
+ xi18n_objects_list = Xmalloc(sizeof(XI18NObjectsListRec) * lc_len);
if (!xi18n_objects_list) return;
}
-/*
-1266793
-Limit the length of path to prevent stack buffer corruption.
- sprintf(filename, "%s/%s", path, "XI18N_OBJS");
-*/
- sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS");
+ snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS");
fp = fopen(filename, "r");
if (fp == (FILE *)NULL){
return;
@@ -212,11 +206,13 @@ Limit the length of path to prevent stack buffer corruption.
}
if (lc_count == lc_len) {
- lc_len += OBJECT_INC_LEN;
- xi18n_objects_list = (XI18NObjectsList)
- Xrealloc(xi18n_objects_list,
- sizeof(XI18NObjectsListRec) * lc_len);
- if (!xi18n_objects_list) return;
+ int new_len = lc_len + OBJECT_INC_LEN;
+ XI18NObjectsListRec *tmp = Xrealloc(xi18n_objects_list,
+ sizeof(XI18NObjectsListRec) * new_len);
+ if (tmp == NULL)
+ goto done;
+ xi18n_objects_list = tmp;
+ lc_len = new_len;
}
n = parse_line(p, args, 6);
@@ -244,6 +240,7 @@ Limit the length of path to prevent stack buffer corruption.
lc_count++;
}
}
+ done:
fclose(fp);
}
@@ -383,9 +380,9 @@ _XlcDynamicLoad(const char *lc_name)
if (lc_name == NULL) return (XLCd)NULL;
- if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL)
+ if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL)
return (XLCd)NULL;
- if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL)
+ if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, lc_name) == NULL)
return (XLCd)NULL;
resolve_object(lc_dir, lc_name);
@@ -512,7 +509,7 @@ _XDynamicUnRegisterIMInstantiateCallback(
XPointer client_data)
{
char lc_dir[BUFSIZE];
- char *lc_name;
+ const char *lc_name;
dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL;
Bool ret_flag = False;
int count;
diff --git a/libX11/src/xlibi18n/XlcPubI.h b/libX11/src/xlibi18n/XlcPubI.h
index 22ac2bdf0..a83d24305 100644
--- a/libX11/src/xlibi18n/XlcPubI.h
+++ b/libX11/src/xlibi18n/XlcPubI.h
@@ -207,13 +207,13 @@ extern int _XlcResolveI18NPath(
extern char *_XlcLocaleLibDirName(
char* /* dir_name */,
size_t, /* dir_len */
- char* /* lc_name */
+ const char* /* lc_name */
);
extern char *_XlcLocaleDirName(
char* /* dir_name */,
size_t, /* dir_len */
- char* /* lc_name */
+ const char* /* lc_name */
);
extern XPointer _XlcCreateLocaleDataBase(
diff --git a/libX11/src/xlibi18n/lcCT.c b/libX11/src/xlibi18n/lcCT.c
index 2fbe8aa88..b1613007d 100644
--- a/libX11/src/xlibi18n/lcCT.c
+++ b/libX11/src/xlibi18n/lcCT.c
@@ -478,7 +478,7 @@ _XlcAddCT(
/* Allocate a CTinfo record. */
length = strlen(ct_sequence);
- ct_info = (CTInfo) Xmalloc(sizeof(CTInfoRec) + length+1);
+ ct_info = Xmalloc(sizeof(CTInfoRec) + length+1);
if (ct_info == NULL)
return charset;
@@ -514,7 +514,7 @@ _XlcAddCT(
Xfree(ct_info);
return charset;
}
- p = (char *) Xmalloc(n+1);
+ p = Xmalloc(n+1);
if (p == NULL) {
Xfree(ct_info);
return charset;
@@ -970,7 +970,7 @@ cstoct(
/* The CompoundText specification says that the only
control characters allowed are 0x09, 0x0a, 0x1b, 0x9b.
Therefore here we eliminate other control characters. */
- unsigned char ch = *((unsigned char *) csptr) & 0x7f;
+ unsigned char ch = *((const unsigned char *) csptr) & 0x7f;
if (!((ch >= min_ch && ch <= max_ch)
|| (side == XlcGL
&& (ch == 0x00 || ch == 0x09 || ch == 0x0a))
@@ -1020,7 +1020,7 @@ cstoct(
#endif
) {
while (csstr_len > 0 && ct_len > 0) {
- unsigned char ch = * (unsigned char *) csptr;
+ unsigned char ch = * (const unsigned char *) csptr;
int char_size = (ch < 0xc0 ? 1 :
ch < 0xe0 ? 2 :
ch < 0xf0 ? 3 :
@@ -1093,9 +1093,9 @@ strtocs(
dst = (char *) *to;
length = min(*from_left, *to_left);
- side = *((unsigned char *) src) & 0x80;
+ side = *((const unsigned char *) src) & 0x80;
- while (side == (*((unsigned char *) src) & 0x80) && length-- > 0)
+ while (side == (*((const unsigned char *) src) & 0x80) && length-- > 0)
*dst++ = *src++;
*from_left -= src - (const char *) *from;
@@ -1140,7 +1140,7 @@ cstostr(
str_len = *to_left;
while (csstr_len > 0 && str_len > 0) {
- ch = *((unsigned char *) csptr++);
+ ch = *((const unsigned char *) csptr++);
csstr_len--;
/* Citing ICCCM: "STRING as a type specifies the ISO Latin-1 character
set plus the control characters TAB and NEWLINE." */
@@ -1169,7 +1169,7 @@ create_conv(
{
XlcConv conv;
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + sizeof(StateRec));
+ conv = Xmalloc(sizeof(XlcConvRec) + sizeof(StateRec));
if (conv == NULL)
return (XlcConv) NULL;
@@ -1187,7 +1187,7 @@ close_converter(
XlcConv conv)
{
/* conv->state is allocated together with conv, free both at once. */
- Xfree((char *) conv);
+ Xfree(conv);
}
diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c
index 5d287811c..0adf0adfc 100644
--- a/libX11/src/xlibi18n/lcCharSet.c
+++ b/libX11/src/xlibi18n/lcCharSet.c
@@ -92,7 +92,7 @@ _XlcAddCharSet(
if (_XlcGetCharSet(charset->name))
return False;
- list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec));
+ list = Xmalloc(sizeof(XlcCharSetListRec));
if (list == NULL)
return False;
@@ -184,9 +184,9 @@ _XlcCreateDefaultCharSet(
ct_sequence_len = strlen(ct_sequence);
/* Fill in name and xrm_name. */
- tmp = (char *) Xmalloc(name_len + 1 + ct_sequence_len + 1);
+ tmp = Xmalloc(name_len + 1 + ct_sequence_len + 1);
if (tmp == NULL) {
- Xfree((char *) charset);
+ Xfree(charset);
return (XlcCharSet) NULL;
}
memcpy(tmp, name, name_len+1);
@@ -196,10 +196,10 @@ _XlcCreateDefaultCharSet(
/* Fill in encoding_name and xrm_encoding_name. */
if ((colon = strchr(charset->name, ':')) != NULL) {
unsigned int length = colon - charset->name;
- char *encoding_tmp = (char *) Xmalloc(length + 1);
+ char *encoding_tmp = Xmalloc(length + 1);
if (encoding_tmp == NULL) {
Xfree((char *) charset->name);
- Xfree((char *) charset);
+ Xfree(charset);
return (XlcCharSet) NULL;
}
memcpy(encoding_tmp, charset->name, length);
diff --git a/libX11/src/xlibi18n/lcConv.c b/libX11/src/xlibi18n/lcConv.c
index 9797e7ed3..7d9a4738c 100644
--- a/libX11/src/xlibi18n/lcConv.c
+++ b/libX11/src/xlibi18n/lcConv.c
@@ -101,7 +101,7 @@ _XlcSetConverter(
}
}
- list = (XlcConverterList) Xmalloc(sizeof(XlcConverterListRec));
+ list = Xmalloc(sizeof(XlcConverterListRec));
if (list == NULL)
return False;
@@ -199,10 +199,10 @@ close_indirect_converter(
if (conv->to_conv)
close_converter(conv->to_conv);
- Xfree((char *) conv);
+ Xfree(conv);
}
- Xfree((char *) lc_conv);
+ Xfree(lc_conv);
}
static void
@@ -250,13 +250,13 @@ open_indirect_converter(
to_type == QChar)
return (XlcConv) NULL;
- lc_conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
+ lc_conv = Xmalloc(sizeof(XlcConvRec));
if (lc_conv == NULL)
return (XlcConv) NULL;
lc_conv->methods = &conv_methods;
- lc_conv->state = (XPointer) Xcalloc(1, sizeof(ConvRec));
+ lc_conv->state = Xcalloc(1, sizeof(ConvRec));
if (lc_conv->state == NULL)
goto err;
diff --git a/libX11/src/xlibi18n/lcDB.c b/libX11/src/xlibi18n/lcDB.c
index 7f13cc3e2..fca9758d8 100644
--- a/libX11/src/xlibi18n/lcDB.c
+++ b/libX11/src/xlibi18n/lcDB.c
@@ -168,7 +168,7 @@ init_parse_info (void)
int size;
if (!allocated) {
bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = (char *)Xmalloc(BUFSIZE);
+ parse_info.buf = Xmalloc(BUFSIZE);
parse_info.bufMaxSize = BUFSIZE;
allocated = 1;
return;
@@ -199,7 +199,7 @@ clear_parse_info (void)
if (*parse_info.value) {
Xfree(*parse_info.value);
}
- Xfree((char *)parse_info.value);
+ Xfree(parse_info.value);
}
ptr = parse_info.buf;
size = parse_info.bufMaxSize;
@@ -213,11 +213,12 @@ realloc_parse_info(
int len)
{
char *p;
+ int newsize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
- parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
- p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize);
+ p = Xrealloc(parse_info.buf, newsize);
if (p == NULL)
return False;
+ parse_info.bufMaxSize = newsize;
parse_info.buf = p;
return True;
@@ -250,9 +251,9 @@ realloc_line(
char *str = line->str;
if (str != NULL) {
- str = (char *)Xrealloc(str, size);
+ str = Xrealloc(str, size);
} else {
- str = (char *)Xmalloc(size);
+ str = Xmalloc(size);
}
if (str == NULL) {
/* malloc error */
@@ -488,7 +489,7 @@ append_value_list (void)
}
if (value_list == (char **)NULL) {
- value_list = (char **)Xmalloc(sizeof(char *) * 2);
+ value_list = Xmalloc(sizeof(char *) * 2);
*value_list = NULL;
} else {
char **prev_list = value_list;
@@ -504,11 +505,11 @@ append_value_list (void)
value = *value_list;
if (value == NULL) {
- value = (char *)Xmalloc(value_len + len + 1);
+ value = Xmalloc(value_len + len + 1);
} else {
char *prev_value = value;
- value = (char *)Xrealloc(value, value_len + len + 1);
+ value = Xrealloc(value, value_len + len + 1);
if (value == NULL) {
Xfree(prev_value);
}
@@ -1035,10 +1036,10 @@ DestroyDatabase(
if (*p->value != NULL) {
Xfree(*p->value);
}
- Xfree((char *)p->value);
+ Xfree(p->value);
}
db = p->next;
- Xfree((char *)p);
+ Xfree(p);
p = db;
}
}
@@ -1251,7 +1252,7 @@ _XlcDestroyLocaleDataBase(
if (p->lc_db == lc_db) {
if ((-- p->ref_count) < 1) {
if (p->lc_db != (XlcDatabase)NULL) {
- Xfree((char *)p->lc_db);
+ Xfree(p->lc_db);
}
DestroyDatabase(p->database);
if (prev == (XlcDatabaseList)NULL) {
@@ -1316,7 +1317,7 @@ _XlcCreateLocaleDataBase(
lc_db[i].db = p;
}
- new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec));
+ new = Xmalloc(sizeof(XlcDatabaseListRec));
if (new == (XlcDatabaseList)NULL) {
goto err;
}
@@ -1333,7 +1334,7 @@ _XlcCreateLocaleDataBase(
err:
DestroyDatabase(database);
if (lc_db != (XlcDatabase)NULL) {
- Xfree((char *)lc_db);
+ Xfree(lc_db);
}
Xfree (name);
return (XPointer)NULL;
diff --git a/libX11/src/xlibi18n/lcDynamic.c b/libX11/src/xlibi18n/lcDynamic.c
index 8d022d885..a50aa70fa 100644
--- a/libX11/src/xlibi18n/lcDynamic.c
+++ b/libX11/src/xlibi18n/lcDynamic.c
@@ -65,8 +65,8 @@ _XlcDynamicLoader(
XLCd lcd;
void *nlshandler;
- sprintf(libpath,"%s/%s/%s",
- XLOCALEDIR,name,LCLIBNAME);
+ snprintf(libpath, sizeof(libpath), "%s/%s/%s",
+ XLOCALEDIR, name, LCLIBNAME);
nlshandler = dlopen(libpath,LAZY);
_XlcGenericMethods = (XLCdMethods)dlsym(nlshandler,"genericMethods");
lcd = _XlcCreateLC(name,_XlcGenericMethods);
diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c
index 51fe8bf1c..c3ea02ead 100644
--- a/libX11/src/xlibi18n/lcFile.c
+++ b/libX11/src/xlibi18n/lcFile.c
@@ -486,9 +486,11 @@ _XlcFileName(
for (i = 0; i < n; ++i) {
char buf[PATH_MAX], *name;
+ if (args[i] == NULL)
+ continue;
+
name = NULL;
- if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) {
- sprintf(buf, "%s/%s.dir", args[i], cat);
+ if (snprintf(buf, PATH_MAX, "%s/%s.dir", args[i], cat) < PATH_MAX) {
name = resolve_name(siname, buf, RtoL);
}
if (name == NULL) {
@@ -498,13 +500,13 @@ _XlcFileName(
/* supposed to be absolute path name */
file_name = name;
} else {
- file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) +
- (name ? strlen (name) : 0));
- if (file_name != NULL)
- sprintf(file_name, "%s/%s", args[i], name);
+ if (snprintf(buf, PATH_MAX, "%s/%s", args[i], name) < PATH_MAX)
+ file_name = strdup(buf);
+ else
+ file_name = NULL;
Xfree(name);
}
- if (isreadable(file_name)) {
+ if (file_name && isreadable(file_name)) {
break;
}
Xfree(file_name);
@@ -535,9 +537,11 @@ _XlcResolveLocaleName(
xlocaledir (dir, PATH_MAX);
n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
for (i = 0; i < n; ++i) {
- if ((2 + (args[i] ? strlen (args[i]) : 0) +
- strlen (locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
+ if (args[i] == NULL)
+ continue;
+
+ if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias)
+ < PATH_MAX) {
name = resolve_name (lc_name, buf, LtoR);
if (!name) {
if (!nlc_name)
@@ -611,14 +615,14 @@ _XlcResolveI18NPath(char *buf, int buf_len)
}
char *
-_XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
+_XlcLocaleDirName(char *dir_name, size_t dir_len, const char *lc_name)
{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ char dir[PATH_MAX], buf[PATH_MAX];
int i, n;
char *args[NUM_LOCALEDIR];
static char locale_alias[] = LOCALE_ALIAS;
- char *target_name = (char*)0;
- char *target_dir = (char*)0;
+ char *target_name = NULL;
+ char *target_dir = NULL;
char *nlc_name = NULL;
static char* last_dir_name = 0;
static size_t last_dir_len = 0;
@@ -631,12 +635,15 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
}
xlocaledir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, 256);
+ n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
for (i = 0; i < n; ++i) {
+ char *name = NULL;
- if ((2 + (args[i] ? strlen(args[i]) : 0) +
- strlen(locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
+ if (args[i] == NULL)
+ continue;
+
+ if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias)
+ < PATH_MAX) {
name = resolve_name(lc_name, buf, LtoR);
if (!name) {
if (!nlc_name)
@@ -646,25 +653,15 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
}
}
- /* If name is not an alias, use lc_name for locale.dir search */
- if (name == NULL)
- name = lc_name;
-
/* look at locale.dir */
target_dir = args[i];
- if (!target_dir) {
- /* something wrong */
- if (name != lc_name)
- Xfree(name);
- continue;
+ if (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) {
+ /* If name is not an alias, use lc_name for locale.dir search */
+ target_name = resolve_name(name ? name : lc_name, buf, RtoL);
}
- if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
- sprintf(buf, "%s/locale.dir", target_dir);
- target_name = resolve_name(name, buf, RtoL);
- }
- if (name != lc_name)
- Xfree(name);
+ Xfree(name);
+ name = NULL;
if (target_name != NULL) {
char *p = 0;
if ((p = strstr(target_name, "/XLC_LOCALE"))) {
@@ -674,27 +671,15 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
Xfree(target_name);
target_name = NULL;
}
- name = NULL;
}
if (nlc_name) Xfree(nlc_name);
- if (target_name == NULL) {
+ if (target_name == NULL)
/* vendor locale name == Xlocale name, no expansion of alias */
- target_dir = args[0];
- target_name = lc_name;
- }
- /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
- strncpy(dir_name, target_dir, dir_len - 1);
- if (strlen(target_dir) >= dir_len - 1) {
- dir_name[dir_len - 1] = '\0';
- } else {
- strcat(dir_name, "/");
- strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
- if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
- dir_name[dir_len - 1] = '\0';
- }
- if (target_name != lc_name)
- Xfree(target_name);
+ snprintf(dir_name, dir_len, "%s/%s", args[0], lc_name);
+ else
+ snprintf(dir_name, dir_len, "%s/%s", target_dir, target_name);
+ Xfree(target_name);
if (last_dir_name != 0)
Xfree (last_dir_name);
@@ -709,14 +694,14 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
}
char *
-_XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
+_XlcLocaleLibDirName(char *dir_name, size_t dir_len, const char *lc_name)
{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ char dir[PATH_MAX], buf[PATH_MAX];
int i, n;
char *args[NUM_LOCALEDIR];
static char locale_alias[] = LOCALE_ALIAS;
- char *target_name = (char*)0;
- char *target_dir = (char*)0;
+ char *target_name = NULL;
+ char *target_dir = NULL;
char *nlc_name = NULL;
static char* last_dir_name = 0;
static size_t last_dir_len = 0;
@@ -729,12 +714,15 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
}
xlocalelibdir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, 256);
+ n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
for (i = 0; i < n; ++i) {
+ char *name = NULL;
+
+ if (args[i] == NULL)
+ continue;
- if ((2 + (args[i] ? strlen(args[i]) : 0) +
- strlen(locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
+ if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias)
+ < PATH_MAX) {
name = resolve_name(lc_name, buf, LtoR);
if (!name) {
if (!nlc_name)
@@ -744,25 +732,15 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
}
}
- /* If name is not an alias, use lc_name for locale.dir search */
- if (name == NULL)
- name = lc_name;
-
/* look at locale.dir */
target_dir = args[i];
- if (!target_dir) {
- /* something wrong */
- if (name != lc_name)
- Xfree(name);
- continue;
- }
- if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
- sprintf(buf, "%s/locale.dir", target_dir);
- target_name = resolve_name(name, buf, RtoL);
+ if (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) {
+ /* If name is not an alias, use lc_name for locale.dir search */
+ target_name = resolve_name(name ? name : lc_name, buf, RtoL);
}
- if (name != lc_name)
- Xfree(name);
+ Xfree(name);
+ name = NULL;
if (target_name != NULL) {
char *p = 0;
if ((p = strstr(target_name, "/XLC_LOCALE"))) {
@@ -772,27 +750,15 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
Xfree(target_name);
target_name = NULL;
}
- name = NULL;
}
if (nlc_name) Xfree(nlc_name);
- if (target_name == NULL) {
+ if (target_name == NULL)
/* vendor locale name == Xlocale name, no expansion of alias */
- target_dir = args[0];
- target_name = lc_name;
- }
- /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
- strncpy(dir_name, target_dir, dir_len - 1);
- if (strlen(target_dir) >= dir_len - 1) {
- dir_name[dir_len - 1] = '\0';
- } else {
- strcat(dir_name, "/");
- strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
- if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
- dir_name[dir_len - 1] = '\0';
- }
- if (target_name != lc_name)
- Xfree(target_name);
+ snprintf(dir_name, dir_len, "%s/%s", args[0], lc_name);
+ else
+ snprintf(dir_name, dir_len, "%s/%s", target_dir, target_name);
+ Xfree(target_name);
if (last_dir_name != 0)
Xfree (last_dir_name);
diff --git a/libX11/src/xlibi18n/lcGeneric.c b/libX11/src/xlibi18n/lcGeneric.c
index bf85bfdbc..13405a65b 100644
--- a/libX11/src/xlibi18n/lcGeneric.c
+++ b/libX11/src/xlibi18n/lcGeneric.c
@@ -69,7 +69,7 @@ create(
if (lcd->core == NULL)
goto err;
- new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
+ new = Xmalloc(sizeof(XLCdPublicMethodsRec));
if (new == NULL)
goto err;
memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
@@ -157,10 +157,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;
@@ -184,10 +184,10 @@ add_codeset(
return NULL;
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;
@@ -231,10 +231,10 @@ add_parse_list(
}
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)
@@ -352,7 +352,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;
@@ -429,17 +429,17 @@ read_charset_define(
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);
@@ -471,21 +471,21 @@ read_charset_define(
/* 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);
@@ -496,7 +496,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);
@@ -505,14 +505,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);
@@ -537,10 +537,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)
@@ -566,10 +566,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 &&
@@ -586,7 +586,7 @@ 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;
@@ -598,7 +598,7 @@ read_segmentconversion(
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;
@@ -610,7 +610,7 @@ read_segmentconversion(
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);
@@ -618,7 +618,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);
@@ -636,9 +636,10 @@ 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 = strdup(value[0]);
@@ -646,7 +647,8 @@ create_ctextseg(
Xfree (ret);
return NULL;
}
- 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);
@@ -658,16 +660,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);
@@ -732,10 +734,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;
@@ -762,7 +764,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)
@@ -773,7 +775,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 {
@@ -809,7 +811,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)
@@ -820,7 +822,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;
@@ -862,7 +864,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) {
@@ -870,8 +872,7 @@ load_generic(
codeset->byteM = NULL;
break ;
}
- codeset->byteM =
- (ByteInfoListRec *)Xmalloc(
+ codeset->byteM = Xmalloc(
(codeset->length)*sizeof(ByteInfoListRec));
if (codeset->byteM == NULL) {
goto err;
@@ -883,7 +884,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 */
@@ -897,7 +898,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);
@@ -909,7 +910,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);
@@ -921,14 +922,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);
diff --git a/libX11/src/xlibi18n/lcPrTxt.c b/libX11/src/xlibi18n/lcPrTxt.c
index 1b7627cf8..47d11f096 100644
--- a/libX11/src/xlibi18n/lcPrTxt.c
+++ b/libX11/src/xlibi18n/lcPrTxt.c
@@ -40,11 +40,11 @@ alloc_list(
if (is_wide_char) {
wchar_t **wstr_list;
- wstr_list = (wchar_t **) Xmalloc(count * sizeof(wchar_t *));
+ wstr_list = Xmalloc(count * sizeof(wchar_t *));
if (wstr_list == NULL)
return (XPointer *) NULL;
- *wstr_list = (wchar_t *) Xmalloc(nitems * sizeof(wchar_t));
+ *wstr_list = Xmalloc(nitems * sizeof(wchar_t));
if (*wstr_list == NULL) {
Xfree(wstr_list);
return (XPointer *) NULL;
@@ -54,11 +54,11 @@ alloc_list(
} else {
char **str_list;
- str_list = (char **) Xmalloc(count * sizeof(char *));
+ str_list = Xmalloc(count * sizeof(char *));
if (str_list == NULL)
return (XPointer *) NULL;
- *str_list = (char *) Xmalloc(nitems);
+ *str_list = Xmalloc(nitems);
if (*str_list == NULL) {
Xfree(str_list);
return (XPointer *) NULL;
@@ -156,7 +156,7 @@ _XTextPropertyToTextList(
else
buf_len = text_prop->nitems * XLC_PUBLIC(lcd, mb_cur_max) + 1;
}
- buf = (XPointer) Xmalloc(buf_len);
+ buf = Xmalloc(buf_len);
if (buf == NULL)
return XNoMemory;
to = buf;
diff --git a/libX11/src/xlibi18n/lcPubWrap.c b/libX11/src/xlibi18n/lcPubWrap.c
index 2a5ac08d8..d1096d570 100644
--- a/libX11/src/xlibi18n/lcPubWrap.c
+++ b/libX11/src/xlibi18n/lcPubWrap.c
@@ -78,7 +78,7 @@ _XlcCreateLC(
return (XLCd) NULL;
if (lcd->core->name == NULL) {
- lcd->core->name = (char*) Xmalloc(strlen(name) + 1);
+ lcd->core->name = Xmalloc(strlen(name) + 1);
if (lcd->core->name == NULL)
goto err;
strcpy(lcd->core->name, name);
diff --git a/libX11/src/xlibi18n/lcPublic.c b/libX11/src/xlibi18n/lcPublic.c
index 12a344272..46c652e2b 100644
--- a/libX11/src/xlibi18n/lcPublic.c
+++ b/libX11/src/xlibi18n/lcPublic.c
@@ -89,7 +89,7 @@ create(
if (lcd->core == NULL)
goto err;
- new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
+ new = Xmalloc(sizeof(XLCdPublicMethodsRec));
if (new == NULL)
goto err;
memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
@@ -107,7 +107,8 @@ load_public(
XLCd lcd)
{
XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
- char **values, *str;
+ char **values;
+ const char *str;
int num;
if(_XlcCreateLocaleDataBase(lcd) == NULL)
diff --git a/libX11/src/xlibi18n/lcRM.c b/libX11/src/xlibi18n/lcRM.c
index 9f72504ee..bdc20f21d 100644
--- a/libX11/src/xlibi18n/lcRM.c
+++ b/libX11/src/xlibi18n/lcRM.c
@@ -85,7 +85,7 @@ ub_destroy(
XPointer state)
{
_XCloseLC(((UbState) state)->lcd);
- Xfree((char *) state);
+ Xfree(state);
}
static const XrmMethodsRec ub_methods = {
@@ -177,7 +177,7 @@ mb_destroy(
{
_XlcCloseConverter(((MbState) state)->conv);
_XCloseLC(((MbState) state)->lcd);
- Xfree((char *) state);
+ Xfree(state);
}
static const XrmMethodsRec mb_methods = {
@@ -197,7 +197,7 @@ _XrmDefaultInitParseInfo(
{
if (XLC_PUBLIC(lcd, mb_cur_max) == 1) {
/* Unibyte case. */
- UbState state = (UbState) Xmalloc(sizeof(UbStateRec));
+ UbState state = Xmalloc(sizeof(UbStateRec));
if (state == NULL)
return (XrmMethods) NULL;
@@ -207,14 +207,14 @@ _XrmDefaultInitParseInfo(
return &ub_methods;
} else {
/* Multibyte case. */
- MbState state = (MbState) Xmalloc(sizeof(MbStateRec));
+ MbState state = Xmalloc(sizeof(MbStateRec));
if (state == NULL)
return (XrmMethods) NULL;
state->lcd = lcd;
state->conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar);
if (state->conv == NULL) {
- Xfree((char *) state);
+ Xfree(state);
return (XrmMethods) NULL;
}
diff --git a/libX11/src/xlibi18n/lcTxtPr.c b/libX11/src/xlibi18n/lcTxtPr.c
index 4dfafe018..05f6a1ffe 100644
--- a/libX11/src/xlibi18n/lcTxtPr.c
+++ b/libX11/src/xlibi18n/lcTxtPr.c
@@ -89,7 +89,7 @@ _XTextListToTextProperty(
is_wide_char = True;
buf_len = get_buf_size(is_wide_char, list, count);
- if ((buf = (char *) Xmalloc(buf_len)) == NULL)
+ if ((buf = Xmalloc(buf_len)) == NULL)
return XNoMemory;
switch (style) {
@@ -194,7 +194,7 @@ retry:
done:
if (nitems <= 0)
nitems = 1;
- value = (char *) Xmalloc(nitems);
+ value = Xmalloc(nitems);
if (value == NULL) {
Xfree(buf);
return XNoMemory;
diff --git a/libX11/src/xlibi18n/lcUTF8.c b/libX11/src/xlibi18n/lcUTF8.c
index 3e934b713..0f3d0d2ca 100644
--- a/libX11/src/xlibi18n/lcUTF8.c
+++ b/libX11/src/xlibi18n/lcUTF8.c
@@ -86,7 +86,7 @@ create_conv(
{
XlcConv conv;
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
+ conv = Xmalloc(sizeof(XlcConvRec));
if (conv == (XlcConv) NULL)
return (XlcConv) NULL;
@@ -100,7 +100,7 @@ static void
close_converter(
XlcConv conv)
{
- Xfree((char *) conv);
+ Xfree(conv);
}
/* Replacement character for invalid multibyte sequence or wide character. */
@@ -498,7 +498,7 @@ create_tocs_conv(
if (charset_num > all_charsets_count-1)
charset_num = all_charsets_count-1;
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)
+ conv = Xmalloc(sizeof(XlcConvRec)
+ (charset_num + 1) * sizeof(Utf8Conv));
if (conv == (XlcConv) NULL)
return (XlcConv) NULL;
@@ -539,7 +539,7 @@ close_tocs_converter(
XlcConv conv)
{
/* conv->state is allocated together with conv, free both at once. */
- Xfree((char *) conv);
+ Xfree(conv);
}
/*
@@ -961,7 +961,7 @@ create_ucstocs_conv(
lazy_init_all_charsets();
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + 2 * sizeof(Utf8Conv));
+ conv = Xmalloc(sizeof(XlcConvRec) + 2 * sizeof(Utf8Conv));
if (conv == (XlcConv) NULL)
return (XlcConv) NULL;
preferred = (Utf8Conv *) ((char *) conv + sizeof(XlcConvRec));
@@ -1731,10 +1731,10 @@ create_tofontcs_conv(
lazy_init_all_charsets();
for (i = 0, num = 0;; i++) {
- sprintf(buf, "fs%d.charset.name", i);
+ snprintf(buf, sizeof(buf), "fs%d.charset.name", i);
_XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
if (count < 1) {
- sprintf(buf, "fs%d.charset", i);
+ snprintf(buf, sizeof(buf), "fs%d.charset", i);
_XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
if (count < 1)
break;
@@ -1742,17 +1742,17 @@ create_tofontcs_conv(
num += count;
}
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + (num + 1) * sizeof(Utf8Conv));
+ conv = Xmalloc(sizeof(XlcConvRec) + (num + 1) * sizeof(Utf8Conv));
if (conv == (XlcConv) NULL)
return (XlcConv) NULL;
preferred = (Utf8Conv *) ((char *) conv + sizeof(XlcConvRec));
/* Loop through all fontsets mentioned in the locale. */
for (i = 0, num = 0;; i++) {
- sprintf(buf, "fs%d.charset.name", i);
+ snprintf(buf, sizeof(buf), "fs%d.charset.name", i);
_XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
if (count < 1) {
- sprintf(buf, "fs%d.charset", i);
+ snprintf(buf, sizeof(buf), "fs%d.charset", i);
_XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
if (count < 1)
break;
diff --git a/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c b/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c
index 1caa28a21..993979aeb 100644
--- a/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c
+++ b/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c
@@ -65,7 +65,7 @@ int main (int argc, char *argv[])
if (argc > 3) {
filename = argv[3];
} else {
- char* s = (char*) malloc(strlen(c_charsetname)+strlen(".h")+1);
+ char* s = malloc(strlen(c_charsetname)+strlen(".h")+1);
strcpy(s,c_charsetname); strcat(s,".h");
filename = s;
}
@@ -361,11 +361,11 @@ int main (int argc, char *argv[])
if (tables[t].usecount > 1) {
char* s;
if (p == tables[t].minline >> 5) {
- s = (char*) malloc(5+1);
+ s = malloc(5+1);
sprintf(s, "%02x_%d", p, ++i);
} else {
p = tables[t].minline >> 5;
- s = (char*) malloc(2+1);
+ s = malloc(2+1);
sprintf(s, "%02x", p);
}
tables[t].suffix = s;
diff --git a/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c b/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c
index 6934789cf..f70fe5e11 100644
--- a/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c
+++ b/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c
@@ -70,9 +70,9 @@ static void read_table (Encoding* enc)
{
int row, col, i, i1, i2, c, j;
- enc->charset2uni = (int**) malloc(enc->rows*sizeof(int*));
+ enc->charset2uni = malloc(enc->rows*sizeof(int*));
for (row = 0; row < enc->rows; row++)
- enc->charset2uni[row] = (int*) malloc(enc->cols*sizeof(int));
+ enc->charset2uni[row] = malloc(enc->cols*sizeof(int));
for (row = 0; row < enc->rows; row++)
for (col = 0; col < enc->cols; col++)
@@ -136,7 +136,7 @@ static void find_charset2uni_pages (Encoding* enc)
{
int row, col;
- enc->charsetpage = (int*) malloc((enc->rows+1)*sizeof(int));
+ enc->charsetpage = malloc((enc->rows+1)*sizeof(int));
for (row = 0; row <= enc->rows; row++)
enc->charsetpage[row] = 0;
@@ -157,7 +157,7 @@ static void find_charset2uni_blocks (Encoding* enc)
{
int n, row, lastrow;
- enc->charsetblocks = (Block*) malloc(enc->rows*sizeof(Block));
+ enc->charsetblocks = malloc(enc->rows*sizeof(Block));
n = 0;
for (row = 0; row < enc->rows; row++)
@@ -266,7 +266,7 @@ static void invert (Encoding* enc)
{
int row, col, j;
- enc->uni2charset = (int*) malloc(0x10000*sizeof(int));
+ enc->uni2charset = malloc(0x10000*sizeof(int));
for (j = 0; j < 0x10000; j++)
enc->uni2charset[j] = 0;
@@ -764,9 +764,9 @@ static void read_table_ksc5601 (Encoding* enc)
{
int row, col, i, i1, i2, c, j;
- enc->charset2uni = (int**) malloc(enc->rows*sizeof(int*));
+ enc->charset2uni = malloc(enc->rows*sizeof(int*));
for (row = 0; row < enc->rows; row++)
- enc->charset2uni[row] = (int*) malloc(enc->cols*sizeof(int));
+ enc->charset2uni[row] = malloc(enc->cols*sizeof(int));
for (row = 0; row < enc->rows; row++)
for (col = 0; col < enc->cols; col++)
diff --git a/libX11/src/xlibi18n/lcWrap.c b/libX11/src/xlibi18n/lcWrap.c
index c3f5ca531..034bd3c0d 100644
--- a/libX11/src/xlibi18n/lcWrap.c
+++ b/libX11/src/xlibi18n/lcWrap.c
@@ -77,20 +77,20 @@ XSetLocaleModifiers(
{
XLCd lcd = _XlcCurrentLC();
char *user_mods;
+ char *mapped_mods;
if (!lcd)
return (char *) NULL;
if (!modifiers)
return lcd->core->modifiers;
user_mods = getenv("XMODIFIERS");
- modifiers = (*lcd->methods->map_modifiers) (lcd,
- user_mods, (char *)modifiers);
- if (modifiers) {
+ mapped_mods = (*lcd->methods->map_modifiers) (lcd, user_mods, modifiers);
+ if (mapped_mods) {
if (lcd->core->modifiers)
Xfree(lcd->core->modifiers);
- lcd->core->modifiers = (char *)modifiers;
+ lcd->core->modifiers = mapped_mods;
}
- return (char *)modifiers;
+ return mapped_mods;
}
Bool
@@ -218,7 +218,7 @@ _XlcAddLoader(
_XlcRemoveLoader(proc); /* remove old loader, if exist */
- loader = (XlcLoaderList) Xmalloc(sizeof(XlcLoaderListRec));
+ loader = Xmalloc(sizeof(XlcLoaderListRec));
if (loader == NULL)
return False;
@@ -293,7 +293,7 @@ _XOpenLC(
for (loader = loader_list; loader; loader = loader->next) {
lcd = (*loader->proc)(name);
if (lcd) {
- cur = (XLCdList) Xmalloc (sizeof(XLCdListRec));
+ cur = Xmalloc (sizeof(XLCdListRec));
if (cur) {
cur->lcd = lcd;
cur->ref_count = 1;
@@ -565,7 +565,7 @@ _XlcVaToArgList(
{
XlcArgList args;
- *args_ret = args = (XlcArgList) Xmalloc(sizeof(XlcArg) * count);
+ *args_ret = args = Xmalloc(sizeof(XlcArg) * count);
if (args == (XlcArgList) NULL)
return;
diff --git a/libX11/src/xlibi18n/mbWMProps.c b/libX11/src/xlibi18n/mbWMProps.c
index bff7aa352..1b3dc970b 100644
--- a/libX11/src/xlibi18n/mbWMProps.c
+++ b/libX11/src/xlibi18n/mbWMProps.c
@@ -61,9 +61,9 @@ XmbSetWMProperties (
XSetWMProperties(dpy, w, wprop, iprop, argv, argc,
sizeHints, wmHints, classHints);
if (wprop)
- Xfree((char *)wname.value);
+ Xfree(wname.value);
if (iprop)
- Xfree((char *)iname.value);
+ Xfree(iname.value);
/* Note: The WM_LOCALE_NAME property is set by XSetWMProperties. */
}
diff --git a/libX11/src/xlibi18n/mbWrap.c b/libX11/src/xlibi18n/mbWrap.c
index 19f01f656..766b8da01 100644
--- a/libX11/src/xlibi18n/mbWrap.c
+++ b/libX11/src/xlibi18n/mbWrap.c
@@ -101,7 +101,7 @@ XmbDrawString(
int text_len)
{
(void)(*font_set->methods->mb_draw_string) (dpy, d, font_set, gc, x, y,
- (char *)text, text_len);
+ text, text_len);
}
@@ -117,7 +117,7 @@ XmbDrawImageString(
int text_len)
{
(*font_set->methods->mb_draw_image_string) (dpy, d, font_set, gc, x, y,
- (char *)text, text_len);
+ text, text_len);
}
int
@@ -126,8 +126,7 @@ XmbTextEscapement(
_Xconst char *text,
int text_len)
{
- return (*font_set->methods->mb_escapement) (font_set,
- (char *)text, text_len);
+ return (*font_set->methods->mb_escapement) (font_set, text, text_len);
}
int
@@ -138,8 +137,7 @@ XmbTextExtents(
XRectangle *overall_ink_extents,
XRectangle *overall_logical_extents)
{
- return (*font_set->methods->mb_extents) (font_set,
- (char *)text, text_len,
+ return (*font_set->methods->mb_extents) (font_set, text, text_len,
overall_ink_extents,
overall_logical_extents);
}
@@ -157,7 +155,7 @@ XmbTextPerCharExtents(
XRectangle *max_logical_extents)
{
return (*font_set->methods->mb_extents_per_char)
- (font_set, (char *)text, text_len,
+ (font_set, text, text_len,
ink_extents_buffer, logical_extents_buffer,
buffer_size, num_chars, max_ink_extents, max_logical_extents);
}
diff --git a/libX11/src/xlibi18n/utf8WMProps.c b/libX11/src/xlibi18n/utf8WMProps.c
index bbfb7c057..80454e66d 100644
--- a/libX11/src/xlibi18n/utf8WMProps.c
+++ b/libX11/src/xlibi18n/utf8WMProps.c
@@ -83,9 +83,9 @@ Xutf8SetWMProperties (
XSetWMProperties(dpy, w, wprop, iprop, argv, argc,
sizeHints, wmHints, classHints);
if (wprop)
- Xfree((char *)wname.value);
+ Xfree(wname.value);
if (iprop)
- Xfree((char *)iname.value);
+ Xfree(iname.value);
/* Note: The WM_LOCALE_NAME property is set by XSetWMProperties. */
}
diff --git a/libX11/src/xlibi18n/utf8Wrap.c b/libX11/src/xlibi18n/utf8Wrap.c
index 82967b0b1..24cb4494c 100644
--- a/libX11/src/xlibi18n/utf8Wrap.c
+++ b/libX11/src/xlibi18n/utf8Wrap.c
@@ -123,7 +123,7 @@ Xutf8DrawString(
int text_len)
{
(void)(*font_set->methods->utf8_draw_string) (dpy, d, font_set, gc, x, y,
- (char *)text, text_len);
+ text, text_len);
}
@@ -139,7 +139,7 @@ Xutf8DrawImageString(
int text_len)
{
(*font_set->methods->utf8_draw_image_string) (dpy, d, font_set, gc, x, y,
- (char *)text, text_len);
+ text, text_len);
}
int
@@ -148,8 +148,7 @@ Xutf8TextEscapement(
_Xconst char *text,
int text_len)
{
- return (*font_set->methods->utf8_escapement) (font_set,
- (char *)text, text_len);
+ return (*font_set->methods->utf8_escapement) (font_set, text, text_len);
}
int
@@ -160,8 +159,7 @@ Xutf8TextExtents(
XRectangle *overall_ink_extents,
XRectangle *overall_logical_extents)
{
- return (*font_set->methods->utf8_extents) (font_set,
- (char *)text, text_len,
+ return (*font_set->methods->utf8_extents) (font_set, text, text_len,
overall_ink_extents,
overall_logical_extents);
}
@@ -179,7 +177,7 @@ Xutf8TextPerCharExtents(
XRectangle *max_logical_extents)
{
return (*font_set->methods->utf8_extents_per_char)
- (font_set, (char *)text, text_len,
+ (font_set, text, text_len,
ink_extents_buffer, logical_extents_buffer,
buffer_size, num_chars, max_ink_extents, max_logical_extents);
}