* gettext-runtime/src/ngettext.c: Include <ctype.h>.
(main): When parsing a nonnegative number, disallow leading whitespace and sign.
* gettext-tools/tests/tstngettext.c: Include <ctype.h>.
(worker_thread): When parsing a nonnegative number, disallow leading whitespace
and sign.
* gnulib-local/lib/markup.c (unescape_string_inplace): When parsing a numeric
character entity, disallow leading whitespace and sign, and report a too large
number as "non-permitted character" rather than "Numerical result out of range".
* gettext-tools/src/msgfmt.c (main): When parsing the '-a' argument, disallow
leading whitespace and sign and check whether the value is a power of 2.
* gettext-tools/src/read-stringtable.c: Include c-ctype.h.
(comment_line_end): When parsing a line number, disallow leading whitespace and
sign.
#include <stdlib.h>
#include <string.h>
#include <locale.h>
+#include <ctype.h>
#include <errno.h>
#include <error.h>
char *endp;
unsigned long tmp_val;
- errno = 0;
- tmp_val = strtoul (count, &endp, 10);
- if (errno == 0 && count[0] != '\0' && endp[0] == '\0')
+ if (isdigit ((unsigned char) count[0])
+ && (errno = 0,
+ tmp_val = strtoul (count, &endp, 10),
+ errno == 0 && endp[0] == '\0'))
n = tmp_val;
else
/* When COUNT is not valid, use plural. */
case '\0': /* Long option. */
break;
case 'a':
- {
- char *endp;
- size_t new_align = strtoul (optarg, &endp, 0);
+ if (isdigit ((unsigned char) optarg[0]))
+ {
+ char *endp;
+ size_t new_align = strtoul (optarg, &endp, 0);
- if (endp != optarg)
- alignment = new_align;
- }
+ if (endp != optarg)
+ /* Check whether new_align is a power of 2. */
+ if (new_align > 0 && (new_align & (new_align - 1)) == 0)
+ alignment = new_align;
+ }
break;
case 'c':
check_domain = true;
/* Reading NeXTstep/GNUstep .strings files.
- Copyright (C) 2003-2024 Free Software Foundation, Inc.
+ Copyright (C) 2003-2025 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
#include "xstrerror.h"
#include "xerror-handler.h"
#include "unistr.h"
+#include "c-ctype.h"
#include "gettext.h"
#define _(str) gettext (str)
if (strlen (line) >= 6 && memcmp (line, "File: ", 6) == 0
&& (last_colon = strrchr (line + 6, ':')) != NULL
- && *(last_colon + 1) != '\0'
+ && c_isdigit (*(last_colon + 1))
&& (number = strtoul (last_colon + 1, &endp, 10), *endp == '\0'))
{
/* A "File: <filename>:<number>" type comment. */
/* ngettext - retrieve plural form strings from message catalog and print them.
- Copyright (C) 1995-2024 Free Software Foundation, Inc.
+ Copyright (C) 1995-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <stdlib.h>
#include <string.h>
#include <locale.h>
+#include <ctype.h>
#include <errno.h>
#include <error.h>
char *endp;
unsigned long tmp_val;
- errno = 0;
- tmp_val = strtoul (count, &endp, 10);
- if (errno == 0 && count[0] != '\0' && endp[0] == '\0')
+ if (isdigit ((unsigned char) count[0])
+ && (errno = 0,
+ tmp_val = strtoul (count, &endp, 10),
+ errno == 0 && endp[0] == '\0'))
n = tmp_val;
else
/* When COUNT is not valid, use plural. */
from++;
}
- errno = 0;
- l = strtoul (from, &end, base);
-
- if (end == from || errno != 0)
+ if (!(base == 16 ? c_isxdigit (*from) : c_isdigit (*from))
+ || (errno = 0,
+ l = strtoul (from, &end, base),
+ end == from))
{
char *error_text =
xasprintf (_("invalid character reference: %s"),
- errno != 0
- ? xstrerror (NULL, errno)
- : _("not a valid number specification"));
+ _("not a valid number specification"));
emit_error (context, error_text);
free (error_text);
return false;
free (error_text);
return false;
}
+ else if (errno == 0
+ /* characters XML 1.1 permits */
+ && ((0 < l && l <= 0xD7FF)
+ || (0xE000 <= l && l <= 0xFFFD) || (0x10000 <= l && l <= 0x10FFFF)))
+ {
+ char buf[8];
+ int length;
+ length = u8_uctomb ((uint8_t *) buf, l, 8);
+ memcpy (to, buf, length);
+ to += length - 1;
+ from = end;
+ if (l >= 0x80) /* not ASCII */
+ mask |= 0x80;
+ }
else
{
- /* characters XML 1.1 permits */
- if ((0 < l && l <= 0xD7FF)
- || (0xE000 <= l && l <= 0xFFFD) || (0x10000 <= l && l <= 0x10FFFF))
- {
- char buf[8];
- int length;
- length = u8_uctomb ((uint8_t *) buf, l, 8);
- memcpy (to, buf, length);
- to += length - 1;
- from = end;
- if (l >= 0x80) /* not ascii */
- mask |= 0x80;
- }
- else
- {
- char *error_text =
- xasprintf (_("invalid character reference: %s"),
- _("non-permitted character"));
- emit_error (context, error_text);
- free (error_text);
- return false;
- }
+ char *error_text =
+ xasprintf (_("invalid character reference: %s"),
+ _("non-permitted character"));
+ emit_error (context, error_text);
+ free (error_text);
+ return false;
}
}