This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug locale/22338] New: locale: Use the right type for allocation sizes (non-portable assumptions).

            Bug ID: 22338
           Summary: locale: Use the right type for allocation sizes
                    (non-portable assumptions).
           Product: glibc
           Version: 2.27
            Status: NEW
          Severity: minor
          Priority: P2
         Component: locale
          Assignee: unassigned at sourceware dot org
          Reporter: carlos at redhat dot com
  Target Milestone: ---

In ld-ctype.c and locfile.c we use the wrong type for sizing the allocation, we
use the sizeof the original type, but that's not correct, it should be the size
of the element size. In both cases we can use the sizeof the dereferenced name
to get the right value.

The oringal code is fine, but it's a non-portable assumption to say that sizeof
(foo **) == sizeof (foo *), it could in theory be different.

We should just fix this.

diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c
index afb431b..b92f857 100644
--- a/locale/programs/ld-ctype.c
+++ b/locale/programs/ld-ctype.c
@@ -3889,7 +3889,7 @@ allocate_arrays (struct locale_ctype_t *ctype, const
struct charmap_t *charmap,

       /* Next we allocate an array large enough and fill in the values.  */
       sorted = (struct translit_t **) alloca (number
-                                             * sizeof (struct translit_t **));
+                                             * sizeof (*sorted));
       runp = ctype->translit;
       number = 0;
diff --git a/locale/programs/locfile.c b/locale/programs/locfile.c
index b52efcf..10e6092 100644
--- a/locale/programs/locfile.c
+++ b/locale/programs/locfile.c
@@ -426,7 +426,7 @@ siblings_uncached (const char *output_path)
          *p++ = '/';
          *p = '\0';
          elems = (const char **) xrealloc ((char *) elems,
-                                           (nelems + 2) * sizeof (char **));
+                                           (nelems + 2) * sizeof (*elems));
          elems[nelems++] = other_path;

You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]