diff options
Diffstat (limited to 'nx-X11/lib/src/xlibi18n')
-rw-r--r-- | nx-X11/lib/src/xlibi18n/ICWrap.c | 5 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/XimProto.h | 4 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/XlcPublic.h | 2 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/Xlcint.h | 4 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/imKStoUCS.c | 6 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcCT.c | 22 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcCharSet.c | 8 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcConv.c | 25 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcDB.c | 53 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcFile.c | 35 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcGeneric.c | 37 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcPrTxt.c | 11 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcPublic.c | 3 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcStd.c | 56 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcTxtPr.c | 12 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcUTF8.c | 50 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcUtil.c | 10 | ||||
-rw-r--r-- | nx-X11/lib/src/xlibi18n/lcWrap.c | 52 |
18 files changed, 189 insertions, 206 deletions
diff --git a/nx-X11/lib/src/xlibi18n/ICWrap.c b/nx-X11/lib/src/xlibi18n/ICWrap.c index 69f080d87..f5caafb97 100644 --- a/nx-X11/lib/src/xlibi18n/ICWrap.c +++ b/nx-X11/lib/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( @@ -84,7 +85,7 @@ _XIMNestedListToNestedList( nlist++; } } - return ptr - list; + return (int) (ptr - list); } static void @@ -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/nx-X11/lib/src/xlibi18n/XimProto.h b/nx-X11/lib/src/xlibi18n/XimProto.h index 6b0096dd6..cc7eda311 100644 --- a/nx-X11/lib/src/xlibi18n/XimProto.h +++ b/nx-X11/lib/src/xlibi18n/XimProto.h @@ -188,9 +188,9 @@ PERFORMANCE OF THIS SOFTWARE. * request packet header size */ #define XIM_HEADER_SIZE \ - sizeof(CARD8) /* sizeof mejor-opcode */ \ + ( sizeof(CARD8) /* sizeof major-opcode */ \ + sizeof(CARD8) /* sizeof minor-opcode */ \ - + sizeof(INT16) /* sizeof length */ + + sizeof(INT16) ) /* sizeof length */ /* * Client Message data size diff --git a/nx-X11/lib/src/xlibi18n/XlcPublic.h b/nx-X11/lib/src/xlibi18n/XlcPublic.h index 3d94ef37d..bab7d6905 100644 --- a/nx-X11/lib/src/xlibi18n/XlcPublic.h +++ b/nx-X11/lib/src/xlibi18n/XlcPublic.h @@ -136,7 +136,7 @@ extern Bool _XlcAddCharSet( /* Retrieves a number of attributes of an XlcCharSet. Return NULL if successful, otherwise the name of the first argument - specifiying a nonexistent attribute. */ + specifying a nonexistent attribute. */ extern char *_XlcGetCSValues( XlcCharSet charset, ... diff --git a/nx-X11/lib/src/xlibi18n/Xlcint.h b/nx-X11/lib/src/xlibi18n/Xlcint.h index 5a6205a1f..196d313f5 100644 --- a/nx-X11/lib/src/xlibi18n/Xlcint.h +++ b/nx-X11/lib/src/xlibi18n/Xlcint.h @@ -655,7 +655,7 @@ typedef struct { /* * An X Input Manager (IM). Implementations may need to extend this data - * structure to accomodate additional data, state information etc. + * structure to accommodate additional data, state information etc. */ typedef struct _XIM { XIMMethods methods; /* method list of this IM */ @@ -739,7 +739,7 @@ typedef struct { /* * an Input Context. Implementations may need to extend this data - * structure to accomodate additional data, state information etc. + * structure to accommodate additional data, state information etc. */ typedef struct _XIC { XICMethods methods; /* method list of this IC */ diff --git a/nx-X11/lib/src/xlibi18n/imKStoUCS.c b/nx-X11/lib/src/xlibi18n/imKStoUCS.c index 640b3516a..a1c591211 100644 --- a/nx-X11/lib/src/xlibi18n/imKStoUCS.c +++ b/nx-X11/lib/src/xlibi18n/imKStoUCS.c @@ -131,8 +131,8 @@ static unsigned short const keysym_to_unicode_8a4_8fe[] = { static unsigned short const keysym_to_unicode_9df_9f8[] = { 0x2422, /* 0x09d8-0x09df */ 0x2666, 0x25a6, 0x2409, 0x240c, 0x240d, 0x240a, 0x0000, 0x0000, /* 0x09e0-0x09e7 */ - 0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x2500, /* 0x09e8-0x09ef */ - 0x0000, 0x0000, 0x0000, 0x0000, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */ + 0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, /* 0x09e8-0x09ef */ + 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */ 0x2502 /* 0x09f8-0x09ff */ }; @@ -285,7 +285,7 @@ KeySymToUcs4(KeySym keysym) return keysym_to_unicode_3a2_3fe[keysym - 0x3a2]; else if (keysym > 0x4a0 && keysym < 0x4e0) return keysym_to_unicode_4a1_4df[keysym - 0x4a1]; - else if (keysym > 0x589 && keysym < 0x5ff) + else if (keysym > 0x58f && keysym < 0x5ff) return keysym_to_unicode_590_5fe[keysym - 0x590]; else if (keysym > 0x67f && keysym < 0x700) return keysym_to_unicode_680_6ff[keysym - 0x680]; diff --git a/nx-X11/lib/src/xlibi18n/lcCT.c b/nx-X11/lib/src/xlibi18n/lcCT.c index a2ff93c8a..15e4ef233 100644 --- a/nx-X11/lib/src/xlibi18n/lcCT.c +++ b/nx-X11/lib/src/xlibi18n/lcCT.c @@ -323,7 +323,7 @@ _XlcParseCharSet( if (*ptr == '\0') return False; - length = strlen(ptr); + length = (int) strlen(ptr); type = _XlcParseCT(&ptr, &length, &final_byte); @@ -428,7 +428,7 @@ _XlcGetCTInfo( && (type != XctExtSeg || (text_len >= ct_info->ext_segment_len && memcmp(text, ct_info->ext_segment, - ct_info->ext_segment_len) == 0))) + (size_t) ct_info->ext_segment_len) == 0))) return ct_info; return (CTInfo) NULL; @@ -477,7 +477,7 @@ _XlcAddCT( } /* Allocate a CTinfo record. */ - length = strlen(ct_sequence); + length = (int) strlen(ct_sequence); ct_info = Xmalloc(sizeof(CTInfoRec) + length+1); if (ct_info == NULL) return charset; @@ -506,7 +506,7 @@ _XlcAddCT( /* By convention, the extended segment name is the encoding_name in lowercase. */ const char *q = charset->encoding_name; - int n = strlen(q); + int n = (int) strlen(q); char *p; /* Ensure ct_info->ext_segment_len <= 0x3fff - 6. */ @@ -802,7 +802,7 @@ cttocs( int n = (state->ext_seg_left <= buf_len ? state->ext_seg_left : (buf_len / char_size) * char_size); - memcpy(bufptr, ctptr, n); + memcpy(bufptr, ctptr, (size_t) n); ctptr += n; ctext_len -= n; bufptr += n; buf_len -= n; state->ext_seg_left -= n; @@ -834,7 +834,7 @@ cttocs( We may be splitting a character into multiple pieces. Oh well. */ int n = buf_len; - memcpy(bufptr, ctptr, n); + memcpy(bufptr, ctptr, (size_t) n); ctptr += n; ctext_len -= n; bufptr += n; buf_len -= n; state->ext_seg_left -= n; @@ -899,7 +899,7 @@ cstoct( return -1; side = charset->side; - length = strlen(ct_info->ct_sequence); + length = (int) strlen(ct_info->ct_sequence); ext_segment_start = NULL; @@ -909,7 +909,7 @@ cstoct( if (ct_len < length + 3) return -1; - memcpy(ctptr, ct_info->ct_sequence, length); + memcpy(ctptr, ct_info->ct_sequence, (size_t) length); ctptr += length; ct_len -= length + 3; } else @@ -924,7 +924,7 @@ cstoct( if (ct_len < length + 2 + ct_info->ext_segment_len) return -1; - memcpy(ctptr, ct_info->ct_sequence, length); + memcpy(ctptr, ct_info->ct_sequence, (size_t) length); ctptr += length; ct_len -= length; @@ -936,14 +936,14 @@ cstoct( if (ct_len > 0x3fff) ct_len = 0x3fff; - memcpy(ctptr, ct_info->ext_segment, ct_info->ext_segment_len); + memcpy(ctptr, ct_info->ext_segment, (size_t) ct_info->ext_segment_len); ctptr += ct_info->ext_segment_len; ct_len -= ct_info->ext_segment_len; } else { if (ct_len < length) return -1; - memcpy(ctptr, ct_info->ct_sequence, length); + memcpy(ctptr, ct_info->ct_sequence, (size_t) length); ctptr += length; ct_len -= length; } diff --git a/nx-X11/lib/src/xlibi18n/lcCharSet.c b/nx-X11/lib/src/xlibi18n/lcCharSet.c index 0adf0adfc..7f1452603 100644 --- a/nx-X11/lib/src/xlibi18n/lcCharSet.c +++ b/nx-X11/lib/src/xlibi18n/lcCharSet.c @@ -121,7 +121,7 @@ static XlcResource resources[] = { /* Retrieves a number of attributes of an XlcCharSet. Return NULL if successful, otherwise the name of the first argument - specifiying a nonexistent attribute. */ + specifying a nonexistent attribute. */ static char * get_values( XlcCharSet charset, @@ -137,7 +137,7 @@ get_values( /* Retrieves a number of attributes of an XlcCharSet. Return NULL if successful, otherwise the name of the first argument - specifiying a nonexistent attribute. */ + specifying a nonexistent attribute. */ char * _XlcGetCSValues(XlcCharSet charset, ...) { @@ -172,7 +172,7 @@ _XlcCreateDefaultCharSet( const char *ct_sequence) { XlcCharSet charset; - int name_len, ct_sequence_len; + size_t name_len, ct_sequence_len; const char *colon; char *tmp; @@ -195,7 +195,7 @@ _XlcCreateDefaultCharSet( /* Fill in encoding_name and xrm_encoding_name. */ if ((colon = strchr(charset->name, ':')) != NULL) { - unsigned int length = colon - charset->name; + size_t length = (size_t)(colon - charset->name); char *encoding_tmp = Xmalloc(length + 1); if (encoding_tmp == NULL) { Xfree((char *) charset->name); diff --git a/nx-X11/lib/src/xlibi18n/lcConv.c b/nx-X11/lib/src/xlibi18n/lcConv.c index 7d9a4738c..32699746d 100644 --- a/nx-X11/lib/src/xlibi18n/lcConv.c +++ b/nx-X11/lib/src/xlibi18n/lcConv.c @@ -29,6 +29,11 @@ #include "Xlibint.h" #include "XlcPubI.h" #include <stdio.h> +#include "locking.h" + +#ifdef XTHREADS +LockInfoPtr _conv_lock; +#endif typedef struct _XlcConverterListRec { XLCd from_lcd; @@ -58,6 +63,9 @@ get_converter( XrmQuark to_type) { XlcConverterList list, prev = NULL; + XlcConv conv = NULL; + + _XLockMutex(_conv_lock); for (list = conv_list; list; list = list->next) { if (list->from_lcd == from_lcd && list->to_lcd == to_lcd @@ -69,13 +77,16 @@ get_converter( conv_list = list; } - return (*list->converter)(from_lcd, list->from, to_lcd, list->to); + conv = (*list->converter)(from_lcd, list->from, to_lcd, list->to); + break; } prev = list; } - return (XlcConv) NULL; + _XUnlockMutex(_conv_lock); + + return conv; } Bool @@ -92,18 +103,20 @@ _XlcSetConverter( from_type = XrmStringToQuark(from); to_type = XrmStringToQuark(to); + _XLockMutex(_conv_lock); + for (list = conv_list; list; list = list->next) { if (list->from_lcd == from_lcd && list->to_lcd == to_lcd && list->from_type == from_type && list->to_type == to_type) { list->converter = converter; - return True; + goto ret; } } list = Xmalloc(sizeof(XlcConverterListRec)); if (list == NULL) - return False; + goto ret; list->from_lcd = from_lcd; list->from = from; @@ -115,7 +128,9 @@ _XlcSetConverter( list->next = conv_list; conv_list = list; - return True; +ret: + _XUnlockMutex(_conv_lock); + return list != NULL; } typedef struct _ConvRec { diff --git a/nx-X11/lib/src/xlibi18n/lcDB.c b/nx-X11/lib/src/xlibi18n/lcDB.c index eb46f8fbd..f25b98c29 100644 --- a/nx-X11/lib/src/xlibi18n/lcDB.c +++ b/nx-X11/lib/src/xlibi18n/lcDB.c @@ -39,6 +39,7 @@ #include <nx-X11/Xresource.h> #include "Xlibint.h" #include "XlcPubI.h" +#include "reallocarray.h" #else /* NOT_X_ENV */ @@ -294,7 +295,7 @@ zap_comment( int pos = p - str; if (pos == 0 || (iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH))) { - int len = strlen(p); + int len = (int) strlen(p); if (len > 0 && (p[len - 1] == SYM_NEWLINE || p[len-1] == SYM_CR)) { /* newline is the identifier for finding end of value. therefore, it should not be removed. */ @@ -326,7 +327,7 @@ read_line( while ((p = fgets(buf, BUFSIZE, fd)) != NULL) { ++line->seq; zap_comment(p, "ed); /* remove comment line */ - len = strlen(p); + len = (int) strlen(p); if (len == 0) { if (cur > 0) { break; @@ -340,7 +341,7 @@ read_line( } str = line->str; } - strncpy(str + cur, p, len); + memcpy(str + cur, p, (size_t) len); cur += len; str[cur] = '\0'; @@ -413,7 +414,7 @@ get_word( } else if (token != T_COMMENT && token != T_DEFAULT) { break; } - strncpy(w, p, token_len); + strncpy(w, p, (size_t) token_len); p += token_len; w += token_len; } *w = '\0'; @@ -448,7 +449,7 @@ get_quoted_word( token = get_token(p); token_len = token_tbl[token].len; } - strncpy(w, p, token_len); + strncpy(w, p, (size_t) token_len); p += token_len; w += token_len; } /* error. cannot detect next double quote */ @@ -483,7 +484,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); } @@ -507,17 +508,19 @@ append_value_list (void) } if (value != *value_list) { int i; - ssize_t delta; - delta = value - *value_list; + char *old_list; + old_list = *value_list; *value_list = value; + /* Re-derive pointers from the new realloc() result to avoid undefined + behaviour (and crashes on architectures with pointer bounds). */ for (i = 1; i < value_num; ++i) { - value_list[i] += delta; + value_list[i] = value + (value_list[i] - old_list); } } value_list[value_num] = p = &value[value_len]; value_list[value_num + 1] = NULL; - strncpy(p, str, len); + strncpy(p, str, (size_t) len); p[len] = 0; parse_info.value = value_list; @@ -551,7 +554,7 @@ construct_name( char *p = name; for (i = 0; i <= parse_info.nest_depth; ++i) { - len += strlen(parse_info.name[i]) + 1; + len = (int) ((size_t) len + (strlen(parse_info.name[i]) + 1)); } if (len >= size) return 0; @@ -655,8 +658,8 @@ check_category_end( while (iswhite(*p)) { ++p; } - len = strlen(parse_info.category); - if (strncmp(p, parse_info.category, len)) { + len = (int) strlen(parse_info.category); + if (strncmp(p, parse_info.category, (size_t) len)) { return 0; } p += len; @@ -806,7 +809,7 @@ f_double_quote( char* wordp; int len; - if ((len = strlen (str)) < sizeof word) + if ((len = (int) strlen (str)) < sizeof word) wordp = word; else wordp = Xmalloc (len + 1); @@ -825,12 +828,12 @@ f_double_quote( goto err; if ((parse_info.bufsize + (int)strlen(wordp) + 1) >= parse_info.bufMaxSize) { - if (realloc_parse_info(strlen(wordp)+1) == False) { + if (realloc_parse_info((int) strlen(wordp)+1) == False) { goto err; } } strcpy(&parse_info.buf[parse_info.bufsize], wordp); - parse_info.bufsize += strlen(wordp); + parse_info.bufsize = (int) ((size_t) parse_info.bufsize + strlen(wordp)); parse_info.pre_state = S_VALUE; break; default: @@ -867,7 +870,7 @@ f_numeric( int len; int token_len; - if ((len = strlen (str)) < sizeof word) + if ((len = (int) strlen (str)) < sizeof word) wordp = word; else wordp = Xmalloc (len + 1); @@ -887,12 +890,12 @@ f_numeric( goto err; if ((parse_info.bufsize + token_len + (int)strlen(wordp) + 1) >= parse_info.bufMaxSize) { - if (realloc_parse_info(token_len + strlen(wordp) + 1) == False) + if (realloc_parse_info((int)((size_t) token_len + strlen(wordp) + 1)) == False) goto err; } - strncpy(&parse_info.buf[parse_info.bufsize], str, token_len); + strncpy(&parse_info.buf[parse_info.bufsize], str, (size_t) token_len); strcpy(&parse_info.buf[parse_info.bufsize + token_len], wordp); - parse_info.bufsize += token_len + strlen(wordp); + parse_info.bufsize = (int) ((size_t) parse_info.bufsize + ((size_t) token_len + strlen(wordp))); parse_info.pre_state = S_VALUE; break; default: @@ -918,7 +921,7 @@ f_default( char* wordp; int len; - if ((len = strlen (str)) < sizeof word) + if ((len = (int) strlen (str)) < sizeof word) wordp = word; else wordp = Xmalloc (len + 1); @@ -945,7 +948,7 @@ f_default( /* end of category is detected. clear context and zap to end of this line */ clear_parse_info(); - len = strlen(str); + len = (int) strlen(str); break; } } @@ -962,11 +965,11 @@ f_default( case S_VALUE: if ((parse_info.bufsize + (int)strlen(wordp) + 1) >= parse_info.bufMaxSize) { - if (realloc_parse_info(strlen(wordp) + 1) == False) + if (realloc_parse_info((int) strlen(wordp) + 1) == False) goto err; } strcpy(&parse_info.buf[parse_info.bufsize], wordp); - parse_info.bufsize += strlen(wordp); + parse_info.bufsize = (int) ((size_t) parse_info.bufsize + strlen(wordp)); parse_info.pre_state = S_VALUE; break; default: @@ -1223,7 +1226,7 @@ _XlcGetLocaleDataBase( /* _XlcDestroyLocaleDataBase(lcd) */ /*----------------------------------------------------------------------*/ /* This function destroy the XLocale Database that bound to the */ -/* specified lcd. If the XLocale Database is refered from some */ +/* specified lcd. If the XLocale Database is referred from some */ /* other lcd, this function just decreases reference count of */ /* the database. If no locale refers the database, this function */ /* remove it from the cache list and free work area. */ diff --git a/nx-X11/lib/src/xlibi18n/lcFile.c b/nx-X11/lib/src/xlibi18n/lcFile.c index cf03a90a7..e4fc8a00b 100644 --- a/nx-X11/lib/src/xlibi18n/lcFile.c +++ b/nx-X11/lib/src/xlibi18n/lcFile.c @@ -36,6 +36,9 @@ /************************************************************************/ +#ifndef HAVE_SETEUID +# define seteuid setuid +#endif #define iscomment(ch) ((ch) == '#' || (ch) == '\0') #if defined(WIN32) #define isreadable(f) (_XAccessFile(f)) @@ -142,7 +145,7 @@ _XlcParsePath( for (i = 0; i < n; ++i) { int len; p = argv[i]; - len = strlen(p); + len = (int) strlen(p); if (len > 0 && p[len - 1] == '/') { /* eliminate trailing slash */ p[len - 1] = '\0'; @@ -172,7 +175,7 @@ xlocaledir( if (dir) { #ifndef WIN32 /* - * Only use the user-supplied path if the process isn't priviledged. + * Only use the user-supplied path if the process isn't privileged. */ if (getuid() == geteuid() && getgid() == getegid()) { #if defined(HASSETUGID) @@ -187,7 +190,7 @@ xlocaledir( } #else /* - * If there are saved ID's the process might still be priviledged + * If there are saved ID's the process might still be privileged * even though the above test succeeded. If issetugid() and * getresgid() aren't available, test this by trying to set * euid to 0. @@ -202,7 +205,7 @@ xlocaledir( priv = 0; } else { if (seteuid(oldeuid) == -1) { - /* XXX ouch, coudn't get back to original uid + /* XXX ouch, couldn't get back to original uid what can we do ??? */ _exit(127); } @@ -214,8 +217,8 @@ xlocaledir( priv = 0; #endif if (!priv) { - len = strlen(dir); - strncpy(p, dir, buf_len); + len = (int) strlen(dir); + strncpy(p, dir, (size_t) buf_len); if (len < buf_len) { p[len++] = LC_PATHDELIM; p += len; @@ -225,7 +228,7 @@ xlocaledir( #endif /* NO_XLOCALEDIR */ if (len < buf_len) - strncpy(p, XLOCALEDIR, buf_len - len); + strncpy(p, XLOCALEDIR, (size_t) (buf_len - len)); buf[buf_len-1] = '\0'; } @@ -246,7 +249,7 @@ xlocalelibdir( if (dir) { #ifndef WIN32 /* - * Only use the user-supplied path if the process isn't priviledged. + * Only use the user-supplied path if the process isn't privileged. */ if (getuid() == geteuid() && getgid() == getegid()) { #if defined(HASSETUGID) @@ -261,7 +264,7 @@ xlocalelibdir( } #else /* - * If there are saved ID's the process might still be priviledged + * If there are saved ID's the process might still be privileged * even though the above test succeeded. If issetugid() and * getresgid() aren't available, test this by trying to set * euid to 0. @@ -276,7 +279,7 @@ xlocalelibdir( priv = 0; } else { if (seteuid(oldeuid) == -1) { - /* XXX ouch, coudn't get back to original uid + /* XXX ouch, couldn't get back to original uid what can we do ??? */ _exit(127); } @@ -288,8 +291,8 @@ xlocalelibdir( priv = 0; #endif if (!priv) { - len = strlen(dir); - strncpy(p, dir, buf_len); + len = (int) strlen(dir); + strncpy(p, dir, (size_t) buf_len); if (len < buf_len) { p[len++] = LC_PATHDELIM; p += len; @@ -299,7 +302,7 @@ xlocalelibdir( #endif /* NO_XLOCALEDIR */ if (len < buf_len) - strncpy(p, XLOCALELIBDIR, buf_len - len); + strncpy(p, XLOCALELIBDIR, (size_t) (buf_len - len)); buf[buf_len-1] = '\0'; } @@ -361,7 +364,7 @@ lowercase( char *t; for (s = src, t = dst; *s; ++s, ++t) - *t = c_tolower(*s); + *t = (char) c_tolower(*s); *t = '\0'; return dst; } @@ -387,7 +390,7 @@ normalize_lcname (const char *name) *p++ = *tmp++; while (*tmp) { if (*tmp != '-') - *p++ = c_tolower(*tmp); + *p++ = (char) c_tolower(*tmp); tmp++; } } @@ -504,7 +507,7 @@ _XlcResolveLocaleName( pub->siname = name; } - sinamelen = strlen (pub->siname); + sinamelen = (int) strlen (pub->siname); if (sinamelen == 1 && pub->siname[0] == 'C') { pub->language = pub->siname; pub->territory = pub->codeset = NULL; diff --git a/nx-X11/lib/src/xlibi18n/lcGeneric.c b/nx-X11/lib/src/xlibi18n/lcGeneric.c index f816fee77..1f3f60bb0 100644 --- a/nx-X11/lib/src/xlibi18n/lcGeneric.c +++ b/nx-X11/lib/src/xlibi18n/lcGeneric.c @@ -34,6 +34,7 @@ #include <stdio.h> #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)); } @@ -275,16 +276,22 @@ free_charset( int num; Xfree(gen->mb_parse_table); + gen->mb_parse_table = NULL; if ((num = gen->mb_parse_list_num) > 0) { for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) { Xfree((*parse_info)->encoding); Xfree(*parse_info); } Xfree(gen->mb_parse_list); + gen->mb_parse_list = NULL; + gen->mb_parse_list_num = 0; } - if ((num = gen->codeset_num) > 0) + if ((num = gen->codeset_num) > 0) { Xfree(gen->codeset_list); + gen->codeset_list = NULL; + gen->codeset_num = 0; + } } /* For VW/UDC */ @@ -350,7 +357,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 +542,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 +674,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); @@ -795,7 +802,7 @@ load_generic( EncodingType type = E_SS; /* for BC */ for (j = 0; shifts[j].str; j++) { if (!_XlcNCompareISOLatin1(tmp, shifts[j].str, - strlen(shifts[j].str))) { + (int) strlen(shifts[j].str))) { type = shifts[j].type; tmp += strlen(shifts[j].str); break; @@ -870,8 +877,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 +889,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/nx-X11/lib/src/xlibi18n/lcPrTxt.c b/nx-X11/lib/src/xlibi18n/lcPrTxt.c index e62e94e80..047eb7f7a 100644 --- a/nx-X11/lib/src/xlibi18n/lcPrTxt.c +++ b/nx-X11/lib/src/xlibi18n/lcPrTxt.c @@ -30,6 +30,7 @@ #include "XlcPubI.h" #include <nx-X11/Xutil.h> #include <nx-X11/Xatom.h> +#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; @@ -99,7 +100,7 @@ copy_list( for (str = *str_list; count > 0; count--, str_list++) { strcpy(str, mb_text); *str_list = str; - length = strlen(str) + 1; + length = (int) strlen(str) + 1; str += length; mb_text += length; } @@ -185,7 +186,7 @@ _XTextPropertyToTextList( if (do_strcpy) { len = min(from_left, to_left); - strncpy(to, from, len); + strncpy(to, from, (size_t) len); from += len; to += len; from_left -= len; diff --git a/nx-X11/lib/src/xlibi18n/lcPublic.c b/nx-X11/lib/src/xlibi18n/lcPublic.c index f35f17a63..1cbc212dc 100644 --- a/nx-X11/lib/src/xlibi18n/lcPublic.c +++ b/nx-X11/lib/src/xlibi18n/lcPublic.c @@ -219,7 +219,7 @@ initialize( * _XlMapOSLocaleName will return the same string or a substring * of name, so strlen(name) is okay */ - if ((len = strlen(name)) < sizeof sinamebuf) + if ((len = (int) strlen(name)) < sizeof sinamebuf) siname = sinamebuf; else siname = Xmalloc (len + 1); @@ -258,6 +258,7 @@ destroy_core( if (lcd) { if (lcd->core) { Xfree(lcd->core->name); + Xfree(lcd->core->modifiers); Xfree(lcd->core); } Xfree(lcd->methods); diff --git a/nx-X11/lib/src/xlibi18n/lcStd.c b/nx-X11/lib/src/xlibi18n/lcStd.c index 9d452bcae..a8518b056 100644 --- a/nx-X11/lib/src/xlibi18n/lcStd.c +++ b/nx-X11/lib/src/xlibi18n/lcStd.c @@ -36,11 +36,11 @@ _Xlcmbtowc( char *str, int len) { - static XLCd last_lcd = NULL; - static XlcConv conv = NULL; + XlcConv conv; XPointer from, to; int from_left, to_left; wchar_t tmp_wc; + int ret; if (lcd == NULL) { lcd = _XlcCurrentLC(); @@ -50,18 +50,9 @@ _Xlcmbtowc( if (str == NULL) return XLC_PUBLIC(lcd, is_state_depend); - if (conv && lcd != last_lcd) { - _XlcCloseConverter(conv); - conv = NULL; - } - - last_lcd = lcd; - - if (conv == NULL) { - conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); - if (conv == NULL) + conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); + if (conv == NULL) return -1; - } from = (XPointer) str; from_left = len; @@ -69,9 +60,12 @@ _Xlcmbtowc( to_left = 1; if (_XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) - return -1; + ret = -1; + else + ret = len - from_left; - return (len - from_left); + _XlcCloseConverter(conv); + return ret; } int @@ -80,10 +74,10 @@ _Xlcwctomb( char *str, wchar_t wc) { - static XLCd last_lcd = NULL; - static XlcConv conv = NULL; + XlcConv conv; XPointer from, to; int from_left, to_left, length; + int ret; if (lcd == NULL) { lcd = _XlcCurrentLC(); @@ -93,18 +87,9 @@ _Xlcwctomb( if (str == NULL) return XLC_PUBLIC(lcd, is_state_depend); - if (conv && lcd != last_lcd) { - _XlcCloseConverter(conv); - conv = NULL; - } - - last_lcd = lcd; - - if (conv == NULL) { - conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte); - if (conv == NULL) - return -1; - } + conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte); + if (conv == NULL) + return -1; from = (XPointer) &wc; from_left = 1; @@ -112,9 +97,12 @@ _Xlcwctomb( length = to_left = XLC_PUBLIC(lcd, mb_cur_max); if (_XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) - return -1; + ret = -1; + else + ret = length - to_left; - return (length - to_left); + _XlcCloseConverter(conv); + return ret; } int @@ -139,7 +127,7 @@ _Xlcmbstowcs( return -1; from = (XPointer) str; - from_left = strlen(str); + from_left = (int) strlen(str); to = (XPointer) wstr; to_left = len; @@ -279,7 +267,7 @@ _Xwcslen( while (*wstr_ptr) wstr_ptr++; - return wstr_ptr - wstr; + return (int) (wstr_ptr - wstr); } int @@ -331,7 +319,7 @@ _Xlcmbstoutf8( return -1; from = (XPointer) str; - from_left = strlen(str); + from_left = (int) strlen(str); to = (XPointer) ustr; to_left = len; diff --git a/nx-X11/lib/src/xlibi18n/lcTxtPr.c b/nx-X11/lib/src/xlibi18n/lcTxtPr.c index cf25e3d0e..102d2917b 100644 --- a/nx-X11/lib/src/xlibi18n/lcTxtPr.c +++ b/nx-X11/lib/src/xlibi18n/lcTxtPr.c @@ -56,7 +56,7 @@ get_buf_size( mb_list = (char **) list; for ( ; count-- > 0; mb_list++) { if (*mb_list) - length += strlen(*mb_list) + 1; + length = (int) ((size_t) length + (strlen(*mb_list) + 1)); } length *= 3; /* XXX */ } @@ -118,7 +118,7 @@ _XTextListToTextProperty( strcpy(to, *mb_list); else *to = '\0'; - from_left = (*mb_list ? strlen(*mb_list) : 0) + 1; + from_left = (int) (*mb_list ? strlen(*mb_list) : 0) + 1; nitems += from_left; to += from_left; mb_list++; @@ -161,7 +161,7 @@ retry: wc_list++; } else { from = (XPointer) *mb_list; - from_left = (*mb_list ? strlen(*mb_list) : 0); + from_left = (int) (*mb_list ? strlen(*mb_list) : 0); mb_list++; } @@ -190,7 +190,7 @@ retry: _XlcCloseConverter(conv); - nitems = to - buf; + nitems = (int) (to - buf); done: if (nitems <= 0) nitems = 1; @@ -202,14 +202,14 @@ done: if (nitems == 1) *value = 0; else - memcpy(value, buf, nitems); + memcpy(value, buf, (size_t) nitems); nitems--; Xfree(buf); text_prop->value = (unsigned char *) value; text_prop->encoding = encoding; text_prop->format = 8; - text_prop->nitems = nitems; + text_prop->nitems = (unsigned long) nitems; return unconv_num; } diff --git a/nx-X11/lib/src/xlibi18n/lcUTF8.c b/nx-X11/lib/src/xlibi18n/lcUTF8.c index 5899338f1..8169608ad 100644 --- a/nx-X11/lib/src/xlibi18n/lcUTF8.c +++ b/nx-X11/lib/src/xlibi18n/lcUTF8.c @@ -163,6 +163,9 @@ typedef struct _Utf8ConvRec { #include "lcUniConv/utf8.h" #include "lcUniConv/ucs2be.h" +#ifdef notused +#include "lcUniConv/ascii.h" +#endif #include "lcUniConv/iso8859_1.h" #include "lcUniConv/iso8859_2.h" #include "lcUniConv/iso8859_3.h" @@ -739,20 +742,14 @@ utf8tocs1( continue; } + last_charset = _XlcGetCharSetWithSide(chosen_charset->name, chosen_side); + if (last_charset == NULL) { - last_charset = - _XlcGetCharSetWithSide(chosen_charset->name, chosen_side); - if (last_charset == NULL) { - src += consumed; - unconv_num++; - continue; - } - } else { - if (!(last_charset->xrm_encoding_name == chosen_charset->xrm_name - && (last_charset->side == XlcGLGR - || last_charset->side == chosen_side))) - break; + src += consumed; + unconv_num++; + continue; } + src += consumed; dst += count; break; @@ -1612,20 +1609,14 @@ wcstocs1( continue; } + last_charset = _XlcGetCharSetWithSide(chosen_charset->name, chosen_side); + if (last_charset == NULL) { - last_charset = - _XlcGetCharSetWithSide(chosen_charset->name, chosen_side); - if (last_charset == NULL) { - src++; - unconv_num++; - continue; - } - } else { - if (!(last_charset->xrm_encoding_name == chosen_charset->xrm_name - && (last_charset->side == XlcGLGR - || last_charset->side == chosen_side))) - break; + src++; + unconv_num++; + continue; } + src++; dst += count; break; @@ -1724,7 +1715,7 @@ create_tofontcs_conv( { XlcConv conv; int i, num, k, count; - char **value, buf[20]; + char **value, buf[32]; Utf8Conv *preferred; lazy_init_all_charsets(); @@ -1931,7 +1922,7 @@ iconv_mbstocs(XlcConv conv, XPointer *from, int *from_left, /* Uses stdc iconv to convert multibyte -> widechar */ - consumed = mbtowc(&wc, (const char *)src, srcend-src); + consumed = mbtowc(&wc, (const char *)src, (size_t) (srcend - src)); if (consumed == 0) break; if (consumed == -1) { @@ -2027,7 +2018,7 @@ iconv_mbtocs(XlcConv conv, XPointer *from, int *from_left, /* Uses stdc iconv to convert multibyte -> widechar */ - consumed = mbtowc(&wc, (const char *)src, srcend-src); + consumed = mbtowc(&wc, (const char *)src, (size_t) (srcend - src)); if (consumed == 0) break; if (consumed == -1) { @@ -2117,7 +2108,7 @@ iconv_mbstostr(XlcConv conv, XPointer *from, int *from_left, /* Uses stdc iconv to convert multibyte -> widechar */ - consumed = mbtowc(&wc, (const char *)src, srcend-src); + consumed = mbtowc(&wc, (const char *)src, (size_t) (srcend - src)); if (consumed == 0) break; if (dst == dstend) @@ -2221,7 +2212,7 @@ iconv_mbstowcs(XlcConv conv, XPointer *from, int *from_left, int length, unconv_num = 0; while (src_left > 0 && dst_left > 0) { - length = mbtowc(dst, src, src_left); + length = mbtowc(dst, src, (size_t) src_left); if (length > 0) { src += length; @@ -2355,6 +2346,7 @@ _XlcAddUtf8LocaleConverters( /* Register converters for XlcNFontCharSet */ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNFontCharSet, open_utf8tofcs); _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNFontCharSet, open_wcstofcs); + _XlcSetConverter(lcd, XlcNUtf8String, lcd, XlcNFontCharSet, open_utf8tofcs); } void diff --git a/nx-X11/lib/src/xlibi18n/lcUtil.c b/nx-X11/lib/src/xlibi18n/lcUtil.c index 52a16daea..30e9c85d9 100644 --- a/nx-X11/lib/src/xlibi18n/lcUtil.c +++ b/nx-X11/lib/src/xlibi18n/lcUtil.c @@ -34,7 +34,7 @@ #define set_toupper(ch) \ if (ch >= 'a' && ch <= 'z') \ - ch = ch - 'a' + 'A'; + ch = (unsigned char) (ch - 'a' + 'A'); /* Compares two ISO 8859-1 strings, ignoring case of ASCII letters. Like strcasecmp in an ASCII locale. */ @@ -46,8 +46,8 @@ _XlcCompareISOLatin1( unsigned char ch1, ch2; for ( ; ; str1++, str2++) { - ch1 = *str1; - ch2 = *str2; + ch1 = (unsigned char) *str1; + ch2 = (unsigned char) *str2; if (ch1 == '\0' || ch2 == '\0') break; set_toupper(ch1); @@ -72,8 +72,8 @@ _XlcNCompareISOLatin1( for ( ; ; str1++, str2++, len--) { if (len == 0) return 0; - ch1 = *str1; - ch2 = *str2; + ch1 = (unsigned char) *str1; + ch2 = (unsigned char) *str2; if (ch1 == '\0' || ch2 == '\0') break; set_toupper(ch1); diff --git a/nx-X11/lib/src/xlibi18n/lcWrap.c b/nx-X11/lib/src/xlibi18n/lcWrap.c index 067c501ba..bc7db1837 100644 --- a/nx-X11/lib/src/xlibi18n/lcWrap.c +++ b/nx-X11/lib/src/xlibi18n/lcWrap.c @@ -66,6 +66,7 @@ from The Open Group. #endif #include <nx-X11/Xutil.h> #include "XlcPubI.h" +#include "reallocarray.h" #ifdef XTHREADS LockInfoPtr _Xi18n_lock; @@ -110,8 +111,8 @@ Bool _XlcValidModSyntax( if (*mods == '@') break; for (ptr = valid_mods; *ptr; ptr++) { - i = strlen(*ptr); - if (strncmp(mods, *ptr, i) || ((mods[i] != '=') + i = (int) strlen(*ptr); + if (strncmp(mods, *ptr, (size_t) i) || ((mods[i] != '=') #ifdef WIN32 && (mods[i] != '#') #endif @@ -140,9 +141,9 @@ _XlcDefaultMapModifiers( return (char *)NULL; if (!_XlcValidModSyntax(user_mods, im_valid)) return (char *)NULL; - i = strlen(prog_mods) + 1; + i = (int) strlen(prog_mods) + 1; if (user_mods) - i += strlen(user_mods); + i = (int) ((size_t) i + strlen(user_mods)); mods = Xmalloc(i); if (mods) { strcpy(mods, prog_mods); @@ -168,7 +169,6 @@ _XlcDefaultMapModifiers( typedef struct _XLCdListRec { struct _XLCdListRec *next; XLCd lcd; - int ref_count; } XLCdListRec, *XLCdList; static XLCdList lcd_list = NULL; @@ -261,7 +261,7 @@ _XOpenLC( * _XlMapOSLocaleName will return the same string or a substring * of name, so strlen(name) is okay */ - if ((len = strlen(name)) >= sizeof sinamebuf) { + if ((len = (int) strlen(name)) >= sizeof sinamebuf) { siname = Xmalloc (len + 1); if (siname == NULL) return NULL; @@ -278,7 +278,6 @@ _XOpenLC( for (cur = lcd_list; cur; cur = cur->next) { if (!strcmp (cur->lcd->core->name, name)) { lcd = cur->lcd; - cur->ref_count++; goto found; } } @@ -295,7 +294,6 @@ _XOpenLC( cur = Xmalloc (sizeof(XLCdListRec)); if (cur) { cur->lcd = lcd; - cur->ref_count = 1; cur->next = lcd_list; lcd_list = cur; } else { @@ -322,23 +320,7 @@ void _XCloseLC( XLCd lcd) { - XLCdList cur, *prev; - - for (prev = &lcd_list; (cur = *prev); prev = &cur->next) { - if (cur->lcd == lcd) { - if (--cur->ref_count < 1) { - (*lcd->methods->close)(lcd); - *prev = cur->next; - Xfree(cur); - } - break; - } - } - - if(loader_list) { - _XlcDeInitLoader(); - loader_list = NULL; - } + (void) lcd; } /* @@ -348,17 +330,7 @@ _XCloseLC( XLCd _XlcCurrentLC(void) { - XLCd lcd; - static XLCd last_lcd = NULL; - - lcd = _XOpenLC((char *) NULL); - - if (last_lcd) - _XCloseLC(last_lcd); - - last_lcd = lcd; - - return lcd; + return _XOpenLC(NULL); } XrmMethods @@ -514,9 +486,9 @@ _XlcCopyFromArg( else if (size == sizeof(XPointer)) *((XPointer *) dst) = (XPointer) src; else if (size > sizeof(XPointer)) - memcpy(dst, (char *) src, size); + memcpy(dst, (char *) src, (size_t) size); else - memcpy(dst, (char *) &src, size); + memcpy(dst, (char *) &src, (size_t) size); } void @@ -540,7 +512,7 @@ _XlcCopyToArg( else if (size == sizeof(XPointer)) *((XPointer *) *dst) = *((XPointer *) src); else - memcpy(*dst, src, size); + memcpy(*dst, src, (size_t) size); } void @@ -564,7 +536,7 @@ _XlcVaToArgList( { XlcArgList args; - *args_ret = args = Xmalloc(sizeof(XlcArg) * count); + *args_ret = args = Xmallocarray(count, sizeof(XlcArg)); if (args == (XlcArgList) NULL) return; |