|
|
Log in / Subscribe / Register

Memory-safe C code

Memory-safe C code

Posted Dec 14, 2025 0:16 UTC (Sun) by alx.manpages (subscriber, #145117)
In reply to: Memory-safe C code by sammythesnake
Parent article: Rust in Android: move fast and fix things (Google Security Blog)

Yup, I got a mistake in the example. It should have been:

void j(size_t n, int a[n])
{
    a[countof(a) - 1] = 42;  // diagnostic
    if (countof(a) >= 1)
        a[countof(a) - 1] = 42;  // ok
    a[countof(a)] = 7;  // diagnostic

    for (int i = 0; i < countof(a); i++)  // ok
        a[i] = 0;
    for (int i = 0; i < countof(a) + 1; i++)  // diagnostic
        a[i] = 0;

    a[42] = 0;  // diagnostic (42 not proved within [0,countof(a)).
}


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds