1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

date_parse.c: trim off

* ext/date/date_parse.c (date_zone_to_diff): trim off by zone name
  length.
This commit is contained in:
Nobuyoshi Nakada 2016-09-30 20:49:58 +09:00
parent d96feee37c
commit 3fc10eff1e
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 10 additions and 13 deletions

View file

@ -438,13 +438,13 @@ date_zone_to_diff(VALUE str)
} }
{ {
long sl = shrunk_size(s, l); long sl = shrunk_size(s, l);
if (sl) { if (sl > 0 && sl <= MAX_WORD_LENGTH) {
char *d = ALLOCV_N(char, vbuf, sl); char *d = ALLOCV_N(char, vbuf, sl);
l = shrink_space(d, s, l); l = shrink_space(d, s, l);
s = d; s = d;
} }
} }
{ if (l > 0 && l <= MAX_WORD_LENGTH) {
const struct zone *z = zonetab(s, (unsigned int)l); const struct zone *z = zonetab(s, (unsigned int)l);
if (z) { if (z) {
int d = z->offset; int d = z->offset;

View file

@ -1,7 +1,7 @@
.SUFFIXES: .list .SUFFIXES: .list
.list.h: .list.h:
gperf --ignore-case -E -C -c -P -p -j1 -i 1 -g -o -t -N $(*F) $< \ gperf --ignore-case -C -c -P -p -j1 -i 1 -g -o -t -N $(*F) $< \
| sed -f $(top_srcdir)/tool/gperf.sed \ | sed -f $(top_srcdir)/tool/gperf.sed \
> $(@F) > $(@F)

View file

@ -1,5 +1,5 @@
/* ANSI-C code produced by gperf version 3.1 */ /* ANSI-C code produced by gperf version 3.1 */
/* Command-line: gperf --ignore-case -E -C -c -P -p -j1 -i 1 -g -o -t -N zonetab zonetab.list */ /* Command-line: gperf --ignore-case -C -c -P -p -j1 -i 1 -g -o -t -N zonetab zonetab.list */
/* Computed positions: -k'1-4,$' */ /* Computed positions: -k'1-4,$' */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
@ -39,6 +39,12 @@ struct zone {
static const struct zone *zonetab(); static const struct zone *zonetab();
#line 9 "zonetab.list" #line 9 "zonetab.list"
struct zone; struct zone;
#define TOTAL_KEYWORDS 170
#define MIN_WORD_LENGTH 1
#define MAX_WORD_LENGTH 17
#define MIN_HASH_VALUE 5
#define MAX_HASH_VALUE 438
/* maximum key range = 434, duplicates = 0 */ /* maximum key range = 434, duplicates = 0 */
#ifndef GPERF_DOWNCASE #ifndef GPERF_DOWNCASE
@ -495,15 +501,6 @@ static const struct stringpool_t stringpool_contents =
const struct zone * const struct zone *
zonetab (register const char *str, register size_t len) zonetab (register const char *str, register size_t len)
{ {
enum
{
TOTAL_KEYWORDS = 170,
MIN_WORD_LENGTH = 1,
MAX_WORD_LENGTH = 17,
MIN_HASH_VALUE = 5,
MAX_HASH_VALUE = 438
};
static const struct zone wordlist[] = static const struct zone wordlist[] =
{ {
{-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},