mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Fix a divide by 0 error when table is too small.
This commit is contained in:
parent
bc82ce348a
commit
6ca5a76286
@ -176,7 +176,9 @@ void *gst_userdata(Gst *vm, uint32_t size, const GstUserType *utype) {
|
|||||||
/* Create a new table */
|
/* Create a new table */
|
||||||
GstTable *gst_table(Gst *vm, uint32_t capacity) {
|
GstTable *gst_table(Gst *vm, uint32_t capacity) {
|
||||||
GstTable *t = gst_alloc(vm, sizeof(GstTable));
|
GstTable *t = gst_alloc(vm, sizeof(GstTable));
|
||||||
GstValue *data = gst_zalloc(vm, capacity * sizeof(GstValue));
|
GstValue *data;
|
||||||
|
if (capacity < 2) capacity = 2;
|
||||||
|
data = gst_zalloc(vm, capacity * sizeof(GstValue));
|
||||||
t->data = data;
|
t->data = data;
|
||||||
t->capacity = capacity;
|
t->capacity = capacity;
|
||||||
t->count = 0;
|
t->count = 0;
|
||||||
|
@ -25,6 +25,3 @@
|
|||||||
'literalsArray []
|
'literalsArray []
|
||||||
'slotMap []
|
'slotMap []
|
||||||
}))
|
}))
|
||||||
|
|
||||||
# Push a scope onto the compiler
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# Pretty print an array or tuple
|
# Pretty print an array or tuple
|
||||||
(: print-seq (fn [start end a seen]
|
(: print-seq (fn [start end a seen]
|
||||||
(: seen (if seen seen {}))
|
(: seen (if seen seen {}))
|
||||||
(if (get seen s) (get seen s)
|
(if (get seen a) (get seen a)
|
||||||
(do
|
(do
|
||||||
(: parts [])
|
(: parts [])
|
||||||
(: len (length a))
|
(: len (length a))
|
||||||
@ -18,7 +18,7 @@
|
|||||||
(if (> len 0) (pop! parts))
|
(if (> len 0) (pop! parts))
|
||||||
(push! parts end)
|
(push! parts end)
|
||||||
(: ret (apply string start parts))
|
(: ret (apply string start parts))
|
||||||
(set! seen s ret)
|
(set! seen a ret)
|
||||||
ret))))
|
ret))))
|
||||||
|
|
||||||
# Pretty print an object or struct
|
# Pretty print an object or struct
|
||||||
@ -53,7 +53,4 @@
|
|||||||
(: h (get handlers (type x)))
|
(: h (get handlers (type x)))
|
||||||
((if h h tostring) x seen)))
|
((if h h tostring) x seen)))
|
||||||
|
|
||||||
(print (pp [1 {4 5 6 7} 2 3]))
|
# (print (pp [1 {4 5 6 7} 2 3]))
|
||||||
|
|
||||||
# Module export pattern - last expression in file is value of module
|
|
||||||
pp
|
|
||||||
|
Loading…
Reference in New Issue
Block a user