aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Anvin <hpa@tazenda.(none)>2005-12-09 10:19:01 -0800
committerPeter Anvin <hpa@tazenda.(none)>2005-12-09 10:19:01 -0800
commit9f91b369501821ea04aff9695be2ce799329c800 (patch)
tree4e4126aa435286c7a61df14db6ab16fd0f48b8a5
parent460efefa6021aed13c6d02479591b0de20fa52bf (diff)
downloadlibucd-9f91b369501821ea04aff9695be2ce799329c800.tar.gz
Make sure errno gets set properly; if _libucd_character_data_raw fails,
propagate failure upwards
-rw-r--r--cache.c5
-rwxr-xr-xgencache.pl3
-rw-r--r--ucslookup.c2
3 files changed, 6 insertions, 4 deletions
diff --git a/cache.c b/cache.c
index 09864e4..c96b67b 100644
--- a/cache.c
+++ b/cache.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <errno.h>
#include "libucd_int.h"
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
@@ -101,8 +102,10 @@ unicode_character_data(int32_t ucs)
const struct unicode_character_data *ucd;
struct cache_row *row;
- if ( ucs < 0 || ucs > 0x10ffff )
+ if ( (uint32_t)ucs > UCS_MAX ) {
+ errno = EINVAL;
return NULL;
+ }
row = &libucd_cache[(uint32_t)ucs % CACHE_ROWS];
diff --git a/gencache.pl b/gencache.pl
index 0d7bb18..d7708cc 100755
--- a/gencache.pl
+++ b/gencache.pl
@@ -60,8 +60,7 @@ for ( $i = 0 ; $i < $associativity ; $i++ ) {
}
print GEN "\tunlock_cache(r); \\\n";
-print GEN "\tucd = _libucd_character_data_raw(u); \\\n";
-print GEN "\t{ \\\n";
+print GEN "\tif ( (ucd = _libucd_character_data_raw(u)) ) { \\\n";
print GEN "\t\tconst struct unicode_character_data *olducd; \\\n";
print GEN "\t\tlock_cache(r); \\\n";
print GEN "\t\tolducd = r->e[$maxent].ucd; \\\n";
diff --git a/ucslookup.c b/ucslookup.c
index f4b534b..973d78a 100644
--- a/ucslookup.c
+++ b/ucslookup.c
@@ -171,7 +171,7 @@ _libucd_character_data_raw(int32_t ucs)
size_t namelen;
struct unicode_character_data *ucd;
- if ( ucs < 0 || ucs > UCS_MAX ) {
+ if ( (uint32_t)ucs > UCS_MAX ) {
errno = EINVAL;
return NULL; /* Invalid UCS value */
}