summary refs log tree commit diff
path: root/pkgs/development/libraries/glibc/loadlocale.patch
blob: 5bd0080520093778821dd3e05468086314a2f2f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
This patch fixes
http://sources.redhat.com/bugzilla/show_bug.cgi?id=356, "localedata:
tests-mbwc/tst_iswalnum segfaults during make check".

===================================================================
RCS file: /cvs/glibc/libc/locale/loadlocale.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- libc/locale/loadlocale.c	2003/09/03 07:54:22	1.44
+++ libc/locale/loadlocale.c	2004/09/26 05:48:14	1.45
@@ -1,5 +1,5 @@
 /* Functions to read locale data files.
-   Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -115,15 +115,45 @@
 	  __set_errno (EINVAL);
 	  return NULL;
 	}
-      if (__builtin_expect (_nl_value_types[category][cnt] == word, 0))
+
+      /* Determine the type.  There is one special case: the LC_CTYPE
+	 category can have more elements than there are in the
+	 _nl_value_type_LC_XYZ array.  There are all pointers.  */
+      switch (category)
+	{
+#define CATTEST(cat) \
+	case LC_##cat:							      \
+	  assert (cnt < (sizeof (_nl_value_type_LC_##cat)		      \
+			 / sizeof (_nl_value_type_LC_##cat[0])));	      \
+	  break
+	  CATTEST (NUMERIC);
+	  CATTEST (TIME);
+	  CATTEST (COLLATE);
+	  CATTEST (MONETARY);
+	  CATTEST (MESSAGES);
+	  CATTEST (PAPER);
+	  CATTEST (NAME);
+	  CATTEST (ADDRESS);
+	  CATTEST (TELEPHONE);
+	  CATTEST (MEASUREMENT);
+	  CATTEST (IDENTIFICATION);
+	default:
+	  assert (category == LC_CTYPE);
+	  break;
+	}
+
+      if ((category == LC_CTYPE
+	   && cnt >= (sizeof (_nl_value_type_LC_CTYPE)
+		      / sizeof (_nl_value_type_LC_CTYPE[0])))
+	  || __builtin_expect (_nl_value_types[category][cnt] != word, 1))
+	newdata->values[cnt].string = newdata->filedata + idx;
+      else
 	{
 	  if (idx % __alignof__ (u_int32_t) != 0)
 	    goto puntdata;
 	  newdata->values[cnt].word =
 	    *((const u_int32_t *) (newdata->filedata + idx));
 	}
-      else
-	newdata->values[cnt].string = newdata->filedata + idx;
     }
 
   return newdata;