Commit e87f0514 by Vicent Martí

Merge pull request #1224 from sba1/some-regex-warning-fixes

Some regex warning fixes
parents 8ace4165 976d9e13
...@@ -542,7 +542,7 @@ weak_alias (__regcomp, regcomp) ...@@ -542,7 +542,7 @@ weak_alias (__regcomp, regcomp)
from either regcomp or regexec. We don't use PREG here. */ from either regcomp or regexec. We don't use PREG here. */
size_t size_t
regerror(int errcode, const regex_t *__restrict preg, regerror(int errcode, UNUSED const regex_t *__restrict preg,
char *__restrict errbuf, size_t errbuf_size) char *__restrict errbuf, size_t errbuf_size)
{ {
const char *msg; const char *msg;
...@@ -1140,7 +1140,7 @@ analyze (regex_t *preg) ...@@ -1140,7 +1140,7 @@ analyze (regex_t *preg)
dfa->subexp_map[i] = i; dfa->subexp_map[i] = i;
preorder (dfa->str_tree, optimize_subexps, dfa); preorder (dfa->str_tree, optimize_subexps, dfa);
for (i = 0; i < preg->re_nsub; i++) for (i = 0; i < preg->re_nsub; i++)
if (dfa->subexp_map[i] != i) if (dfa->subexp_map[i] != (int)i)
break; break;
if (i == preg->re_nsub) if (i == preg->re_nsub)
{ {
...@@ -1358,7 +1358,7 @@ calc_first (void *extra, bin_tree_t *node) ...@@ -1358,7 +1358,7 @@ calc_first (void *extra, bin_tree_t *node)
/* Pass 2: compute NEXT on the tree. Preorder visit. */ /* Pass 2: compute NEXT on the tree. Preorder visit. */
static reg_errcode_t static reg_errcode_t
calc_next (void *extra, bin_tree_t *node) calc_next (UNUSED void *extra, bin_tree_t *node)
{ {
switch (node->token.type) switch (node->token.type)
{ {
...@@ -1609,7 +1609,8 @@ calc_inveclosure (re_dfa_t *dfa) ...@@ -1609,7 +1609,8 @@ calc_inveclosure (re_dfa_t *dfa)
static reg_errcode_t static reg_errcode_t
calc_eclosure (re_dfa_t *dfa) calc_eclosure (re_dfa_t *dfa)
{ {
int node_idx, incomplete; size_t node_idx;
int incomplete;
#ifdef DEBUG #ifdef DEBUG
assert (dfa->nodes_len > 0); assert (dfa->nodes_len > 0);
#endif #endif
...@@ -3308,7 +3309,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, ...@@ -3308,7 +3309,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
static reg_errcode_t static reg_errcode_t
parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp, parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
re_token_t *token, int token_len, re_dfa_t *dfa, re_token_t *token, int token_len, UNUSED re_dfa_t *dfa,
reg_syntax_t syntax, int accept_hyphen) reg_syntax_t syntax, int accept_hyphen)
{ {
#ifdef RE_ENABLE_I18N #ifdef RE_ENABLE_I18N
...@@ -3803,7 +3804,7 @@ free_token (re_token_t *node) ...@@ -3803,7 +3804,7 @@ free_token (re_token_t *node)
and its children. */ and its children. */
static reg_errcode_t static reg_errcode_t
free_tree (void *extra, bin_tree_t *node) free_tree (UNUSED void *extra, bin_tree_t *node)
{ {
free_token (&node->token); free_token (&node->token);
return REG_NOERROR; return REG_NOERROR;
......
...@@ -27,6 +27,14 @@ ...@@ -27,6 +27,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifndef UNUSED
#ifdef __GNUC__
#define UNUSED __attribute__((unused))
#endif
#else
#define UNUSED
#endif
#if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC #if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
# include <langinfo.h> # include <langinfo.h>
#endif #endif
...@@ -171,8 +179,9 @@ extern const size_t __re_error_msgid_idx[] attribute_hidden; ...@@ -171,8 +179,9 @@ extern const size_t __re_error_msgid_idx[] attribute_hidden;
typedef unsigned long int bitset_word_t; typedef unsigned long int bitset_word_t;
/* All bits set in a bitset_word_t. */ /* All bits set in a bitset_word_t. */
#define BITSET_WORD_MAX ULONG_MAX #define BITSET_WORD_MAX ULONG_MAX
/* Number of bits in a bitset_word_t. */ /* Number of bits in a bitset_word_t. Cast to int as most code use it
#define BITSET_WORD_BITS (sizeof (bitset_word_t) * CHAR_BIT) * like that for counting */
#define BITSET_WORD_BITS ((int)(sizeof (bitset_word_t) * CHAR_BIT))
/* Number of bitset_word_t in a bit_set. */ /* Number of bitset_word_t in a bit_set. */
#define BITSET_WORDS (SBC_MAX / BITSET_WORD_BITS) #define BITSET_WORDS (SBC_MAX / BITSET_WORD_BITS)
typedef bitset_word_t bitset_t[BITSET_WORDS]; typedef bitset_word_t bitset_t[BITSET_WORDS];
......
...@@ -689,7 +689,7 @@ re_search_internal (const regex_t *preg, ...@@ -689,7 +689,7 @@ re_search_internal (const regex_t *preg,
if (nmatch > 1 || dfa->has_mb_node) if (nmatch > 1 || dfa->has_mb_node)
{ {
/* Avoid overflow. */ /* Avoid overflow. */
if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0)) if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= (size_t)mctx.input.bufs_len, 0))
{ {
err = REG_ESPACE; err = REG_ESPACE;
goto free_return; goto free_return;
...@@ -920,7 +920,7 @@ re_search_internal (const regex_t *preg, ...@@ -920,7 +920,7 @@ re_search_internal (const regex_t *preg,
if (dfa->subexp_map) if (dfa->subexp_map)
for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++) for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++)
if (dfa->subexp_map[reg_idx] != reg_idx) if (dfa->subexp_map[reg_idx] != (int)reg_idx)
{ {
pmatch[reg_idx + 1].rm_so pmatch[reg_idx + 1].rm_so
= pmatch[dfa->subexp_map[reg_idx] + 1].rm_so; = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so;
...@@ -953,7 +953,7 @@ prune_impossible_nodes (re_match_context_t *mctx) ...@@ -953,7 +953,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
halt_node = mctx->last_node; halt_node = mctx->last_node;
/* Avoid overflow. */ /* Avoid overflow. */
if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0)) if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= (size_t)match_last, 0))
return REG_ESPACE; return REG_ESPACE;
sifted_states = re_malloc (re_dfastate_t *, match_last + 1); sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
...@@ -3375,7 +3375,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) ...@@ -3375,7 +3375,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
/* Avoid arithmetic overflow in size calculation. */ /* Avoid arithmetic overflow in size calculation. */
if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX) if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
/ (3 * sizeof (re_dfastate_t *))) / (3 * sizeof (re_dfastate_t *)))
< ndests), < (size_t)ndests),
0)) 0))
goto out_free; goto out_free;
...@@ -4099,7 +4099,7 @@ extend_buffers (re_match_context_t *mctx) ...@@ -4099,7 +4099,7 @@ extend_buffers (re_match_context_t *mctx)
re_string_t *pstr = &mctx->input; re_string_t *pstr = &mctx->input;
/* Avoid overflow. */ /* Avoid overflow. */
if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0)) if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= (size_t)pstr->bufs_len, 0))
return REG_ESPACE; return REG_ESPACE;
/* Double the lengthes of the buffers. */ /* Double the lengthes of the buffers. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment