summaryrefslogtreecommitdiff
path: root/util/cairo-script
diff options
context:
space:
mode:
authorM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>2008-12-08 09:23:37 +0200
committerChris Wilson <chris@chris-wilson.co.uk>2008-12-12 12:00:41 +0000
commit620028fd19b091f525964b689ebd3a70e1636da2 (patch)
treec5cd213f1b7ba4bde11471dceaab7535aa93176a /util/cairo-script
parent4ba77f776509caad030edf818a076ea9b071ad23 (diff)
downloadcairo-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.c11
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