aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/src/xlibi18n/lcDB.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/lib/src/xlibi18n/lcDB.c')
-rw-r--r--nx-X11/lib/src/xlibi18n/lcDB.c53
1 files changed, 28 insertions, 25 deletions
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, &quoted); /* 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. */