diff options
author | M Joonas Pihlaja <jpihlaja@cc.helsinki.fi> | 2008-12-08 09:23:37 +0200 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-12-12 12:00:41 +0000 |
commit | 620028fd19b091f525964b689ebd3a70e1636da2 (patch) | |
tree | c5cd213f1b7ba4bde11471dceaab7535aa93176a /util/cairo-script | |
parent | 4ba77f776509caad030edf818a076ea9b071ad23 (diff) | |
download | cairo-620028fd19b091f525964b689ebd3a70e1636da2.tar.gz |
[script] Don't segfault when hashing empty strings.
Check for the empty string.
Diffstat (limited to 'util/cairo-script')
-rw-r--r-- | util/cairo-script/cairo-script-interpreter.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/util/cairo-script/cairo-script-interpreter.c b/util/cairo-script/cairo-script-interpreter.c index fea6a4add..8f8af9062 100644 --- a/util/cairo-script/cairo-script-interpreter.c +++ b/util/cairo-script/cairo-script-interpreter.c @@ -221,12 +221,15 @@ static unsigned long _intern_string_hash (const char *str, int len) { const signed char *p = (const signed char *) str; - unsigned int h = *p; + if (len > 0) { + unsigned int h = *p; - for (p += 1; --len; p++) - h = (h << 5) - h + *p; + while (--len) + h = (h << 5) - h + *++p; - return h; + return h; + } + return 0; } static cairo_bool_t |