diff options
| author | Tyge Løvset <[email protected]> | 2021-11-21 15:04:07 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-11-21 15:04:07 +0100 |
| commit | 422272d1d87921b4524bdb276862687bf11b344d (patch) | |
| tree | 6c9bcee00f08ea9953f2d8bfff8c405f02af1686 /include/stc/cstack.h | |
| parent | 835a3a974f4f79ca789d6fca6c9745b4f4931870 (diff) | |
| download | STC-modified-422272d1d87921b4524bdb276862687bf11b344d.tar.gz STC-modified-422272d1d87921b4524bdb276862687bf11b344d.zip | |
Changed reverse() and resize() to return false if mem alloc failed.
Diffstat (limited to 'include/stc/cstack.h')
| -rw-r--r-- | include/stc/cstack.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index a57dfcb8..099c2869 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -76,9 +76,10 @@ STC_INLINE _cx_value* _cx_memb(_top)(const _cx_self* self) STC_INLINE void _cx_memb(_pop)(_cx_self* self)
{ _cx_value* p = &self->data[--self->size]; i_valdel(p); }
-STC_INLINE void _cx_memb(_reserve)(_cx_self* self, size_t n) {
- if (n >= self->size)
- self->data = (_cx_value *)c_realloc(self->data, (self->capacity = n)*sizeof(_cx_value));
+STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) {
+ if (n < self->size) return true;
+ _cx_value *t = (_cx_value *)c_realloc(self->data, n*sizeof *t);
+ return t ? (self->data = t, self->capacity = n) : 0;
}
STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self)
|
