Example: malloc0.c

up: index
prev: memcpy3.c
next: calloc0.c

    #include <stdlib.h>
    #include <stdio.h>
    #include <stdalign.h>
    #include <inttypes.h>
    #include <cheriintrin.h>
    #include <stddef.h>
    
    int main()
    {
        for(unsigned long i=0;i<20;i++)
        {
            void *p = malloc(i);
            ptraddr_t a = cheri_address_get(p);
            if(a % alignof(max_align_t) != 0)
            {
                fprintf(stderr,"not sufficiently aligned pointer\n");
                return(1);
            }
            if(cheri_offset_get(p) != 0)
            {
                fprintf(stderr,"non-zero offset\n");
                return(1);
            }
            if(cheri_length_get(p) < i)
            {
                fprintf(stderr,"allocation too small\n");
                return(1);
            }
            free(p);
        }
        fprintf(stderr,"OK\n");
    }

Experimental data (what does this mean?)

gcc-morello-O0
gcc-morello-O3
clang-morello-O0-bounds-conservative
clang-morello-O3-bounds-conservative
clang-morello-O0-bounds-references-only
clang-morello-O0-bounds-subobject-safe
clang-morello-O3-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
clang-riscv-O0-bounds-conservative
clang-riscv-O3-bounds-conservative
clang-riscv-O0-bounds-references-only
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O3-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
cerberus-cheri
cerberus-cheri-no-pnvi
cerberus-cheri-revocation
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia
cerberus-cheri-cornucopia-no-pnvi
 OK