[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] [PATCH] alist-update: don't segfault on non-list
From: |
Jim Ursetto |
Subject: |
Re: [Chicken-hackers] [PATCH] alist-update: don't segfault on non-list |
Date: |
Sat, 16 Mar 2013 16:51:25 -0500 |
I don't believe that will work; the list check must be done
inside the loop. Otherwise this will crash:
(alist-update 'foo 'bar '((a . b) . 3))
This should also be true for alist-update! as well
(i.e. replace (and (pair? lst) ...) with ##sys#check)
or the one I showed below won't error out:
(alist-update! 'foo 'bar '((a . b) 3 (c . d)) (cut equal? <> <>))
On Mar 16, 2013, at 3:16 PM, Christian Kellermann wrote:
> * Jim Ursetto <address@hidden> [130314 08:13]:
>> Nice catch. Actually, it might be better rewritten with (##sys#check-list
>> lst 'alist-update), although that is not that important.
>>
>> Related, alist-update! behaves weird but doesn't crash on non-alists:
>>
>> (alist-update! 'foo 'bar 3)
>> ;=> ((foo . bar) . 3)
>>
>> And it's inconsistent when you give it a comparator:
>>
>> ;; this uses assoc
>> (alist-update! 'foo 'bar '((a . b) 3 (c . d)) equal?)
>> Error: (assoc) bad argument type: 3
>>
>> ;; this uses an assoc-like loop which does not check for lists
>> (alist-update! 'foo 'bar '((a . b) 3 (c . d)) (cut equal? <> <>))
>> ;=> ((foo . bar) (a . b) 3 (c . d))
>>
>
> I propose the following patch, which checks the argument for both
> procedures with the usual ##sys#check...
>
> Kind regards,
>
> Christian
>
> --
> In the world, there is nothing more submissive and weak than
> water. Yet for attacking that which is hard and strong, nothing can
> surpass it. --- Lao Tzu
> <0001-alist-update-don-t-segfault-on-non-list.patch>