plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

commit e41871a7f002985778ff974832ca5b8bcabb2443
parent edbdfca9ae880879e0830f8eaf2a37abaeca4b54
Author: ssnf <ssnf@ssnf.xyz>
Date:   Thu, 31 Jul 2025 21:26:54 +0000

libvec: sysfatal on nil pointers

Diffstat:
Msrc/libvec/Vecadd.c | 4++++
Msrc/libvec/Vecdel.c | 4++++
Msrc/libvec/Vecinit.c | 6++++++
Msrc/libvec/Veczero.c | 2++
4 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/libvec/Vecadd.c b/src/libvec/Vecadd.c @@ -7,6 +7,8 @@ Vecadd_(Type *p, ulong ms) { Vector *v; + if (!p) + sysfatal("Vecadd: nil pointer"); Vecinsure_(p, ms, Vecsiz(*p) + 1); v = Vec(*p); if (v->init) @@ -21,6 +23,8 @@ Vecinsure_(Type *p, ulong ms, ulong n) { Vector *v; + if (!p) + sysfatal("Vecinsure: nil pointer"); v = Vec(*p); if (v->size >= n) return; diff --git a/src/libvec/Vecdel.c b/src/libvec/Vecdel.c @@ -8,9 +8,13 @@ Vecdel_(Type *p, ulong ms, ulong n) Vector *v; char *q; + if (!p) + sysfatal("Vecdel: nil pointer"); v = Vec(*p); if (!v->n) return; + if (n >= v->n) + sysfatal("Vecdel: out of bounds"); q = (char*)*p + n * ms; if (v->close) v->close(q); diff --git a/src/libvec/Vecinit.c b/src/libvec/Vecinit.c @@ -5,6 +5,8 @@ Vector* Vec(Type p) { + if (!p) + sysfatal("Vec: nil pointer"); return (Vector*)p - 1; } @@ -13,6 +15,8 @@ Vecinit_(Type *p, ulong ms, void (*init)(), void (*close)()) { Vector *v; + if (!p) + sysfatal("Vecinit: nil pointer"); v = malloc(sizeof(*v)); if (!v) sysfatal("libvec vec.c:malloc(): %r"); @@ -28,6 +32,8 @@ Vecclose_(Type *p, ulong ms) { Vector *v; + if (!p) + sysfatal("Vecclose: nil pointer"); v = Vec(*p); if (v->close) for (;v->n;) diff --git a/src/libvec/Veczero.c b/src/libvec/Veczero.c @@ -8,6 +8,8 @@ Veczero_(Type *p, ulong ms) { Vector *v; + if (!p) + sysfatal("Veczero: nil pointer"); v = Vec(*p); if (v->close != NULL) for (;v->n;)