Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Feb 2023 16:31:14 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 269688] memalign() produces division by zero if size is 0
Message-ID:  <bug-269688-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D269688

            Bug ID: 269688
           Summary: memalign() produces division by zero if size is 0
           Product: Base System
           Version: 13.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: pjfloyd@wanadoo.fr

The implementation is to just call aligned_alloc():

        return (aligned_alloc(align, roundup(size, align)));

where roundup is this macro

:#define        roundup(x, y)   ((((x)+((y)-1))/(y))*(y))  /* to any y */

If size is 0 that will be

   (0 + align - 1) / 0 * 0


That gives me

(gdb) r
Starting program: /usr/home/paulf/scratch/valgrind/memcheck/tests/memalign2=
=20

Program received signal SIGFPE, Arithmetic exception.
Integer divide by zero.
0x00000008002f3415 in memalign (align=3D0, size=3D<optimized out>) at
/usr/src/lib/libc/gen/memalign.c:39
39              return (aligned_alloc(align, roundup(size, align)));

My source code is

91         p =3D memalign(0, 100);      assert(NULL =3D=3D p);

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-269688-227>