Example: realloc4.c

up: index
prev: realloc3.c
next: stack0.c

    #include <stdlib.h>
    #include <stdio.h>
    #include <inttypes.h>
    #include <cheriintrin.h>
    #include <stddef.h>
    #include "capprint.h"
    
    int main()
    {
        int *p = calloc(10,sizeof(int));
        *p=42;
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)p));
        p = cheri_bounds_set(p, 1);
        fprintf(stderr,"Modified: %" PTR_FMT "\n", sptr((void*)p));
        p = realloc(p, 20*sizeof(int));
        fprintf(stderr,"Reallocated: %" PTR_FMT "\n", sptr((void*)p));
        fprintf(stderr,"Value: %d\n", *p);
    }

Experimental data (what does this mean?)

cerberus-cheri-no-pnvi
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia-no-pnvi
 exit codes: compile 0 / execute 1 Undefined {ub: "UB179a_non_matching_allocation_free", loc: "<15:5--15:6>"}
Original: (@disabled, 0xffffe6a0 [rwRW,0xffffe6a0-0xffffe6c8])
Modified: (@disabled, 0xffffe6a0 [rwRW,0xffffe6a0-0xffffe6a1])
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 exit codes: compile 0 / execute 1 Undefined {ub: "UB179c_non_matching_allocation_realloc", loc: "<15:5--15:6>"}
Original: (@88, 0xffffe6a0 [rwRW,0xffffe6a0-0xffffe6c8])
Modified: (@88, 0xffffe6a0 [rwRW,0xffffe6a0-0xffffe6a1])
 
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
 Original: 0x40a1d000 [rwRW,0x40a1d000-0x40a1d028]
Modified: 0x40a1d000 [rwRW,0x40a1d000-0x40a1d001]
Reallocated: 0x40a21000 [rwRW,0x40a21000-0x40a21050]
Value: 42
 
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
 Original: 0x40c1d000 [rwRW,0x40c1d000-0x40c1d028]
Modified: 0x40c1d000 [rwRW,0x40c1d000-0x40c1d001]
Reallocated: 0x40c21000 [rwRW,0x40c21000-0x40c21050]
Value: 42
 
gcc-morello-O0
gcc-morello-O3
 Original: 0x40000010 [rwRW,0x40000010-0x40000038]
Modified: 0x40000010 [rwRW,0x40000010-0x40000011]
Reallocated: 0x40000260 [rwRW,0x40000260-0x400002b0]
Value: 42