Csound Csound-dev Csound-tekno Search About

[Csnd-dev] is this a bug?

Date2018-10-03 13:18
Fromjoachim heintz
Subject[Csnd-dev] is this a bug?
this code prevents kIndx from increasing more than 5:

instr 1
kArr[] init 5
kIndx = 0
while kIndx < 10 do ;try kIndx < 5 instead
  kArr[kIndx] = 1
  printk2 kIndx
  kIndx += 1
od
turnoff
endin


csound here looks for the array length and holds kIndx to length-1.

i would expect that kIndx can increment nevertheless but the internal 
array index is limited to the maximum of length-1.

am i wrong?  is this as expected?


best -

Date2018-10-03 13:38
FromMauro Giubileo
SubjectRe: [Csnd-dev] is this a bug?

I don't know how Csound manages internally these situations, but normally I would expect that you'll have a segmentation fault, being that you have declared an array of 5 elements, but then you try to access to elements beyond the allocated size for the array...

Regards,
Mauro

Il 2018-10-03 14:18 joachim heintz ha scritto:

this code prevents kIndx from increasing more than 5:

instr 1
kArr[] init 5
kIndx = 0
while kIndx < 10 do ;try kIndx < 5 instead
 kArr[kIndx] = 1
 printk2 kIndx
 kIndx += 1
od
turnoff
endin


csound here looks for the array length and holds kIndx to length-1.

i would expect that kIndx can increment nevertheless but the internal array index is limited to the maximum of length-1.

am i wrong?  is this as expected?


best -
    joachim

Date2018-10-03 14:07
Fromjoachim heintz
SubjectRe: [Csnd-dev] is this a bug?
to prevent this segfault, csound has a boundary check for arrays and tables.

but should the boundary check really affect the variable, or only the 
reference in the array?

obviously csound makes no difference here ...



On 03/10/18 14:38, Mauro Giubileo wrote:
> I don't know how Csound manages internally these situations, but
> normally I would expect that you'll have a segmentation fault, being
> that you have declared an array of 5 elements, but then you try to
> access to elements beyond the allocated size for the array...
>
> Regards,
> Mauro
>
> Il 2018-10-03 14:18 joachim heintz ha scritto:
>
>> this code prevents kIndx from increasing more than 5:
>>
>> instr 1
>> kArr[] init 5
>> kIndx = 0
>> while kIndx < 10 do ;try kIndx < 5 instead
>>  kArr[kIndx] = 1
>>  printk2 kIndx
>>  kIndx += 1
>> od
>> turnoff
>> endin
>>
>>
>> csound here looks for the array length and holds kIndx to length-1.
>>
>> i would expect that kIndx can increment nevertheless but the internal
>> array index is limited to the maximum of length-1.
>>
>> am i wrong?  is this as expected?
>>
>>
>> best -

Date2018-10-03 14:21
FromVictor Lazzarini
SubjectRe: [Csnd-dev] is this a bug?
That’s how the code was written. The opcode returns an error code and the rest of the instrument stops executing for
the rest of the k-cycle. Whether that is how it should be or not, I don’t know. If we stuck a PerfError() then the instrument
would be stopped. Not sure again if it is too much.

Not signalling is an error might possibly be misleading too.

 
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 3 Oct 2018, at 13:18, joachim heintz  wrote:
> 
> this code prevents kIndx from increasing more than 5:
> 
> instr 1
> kArr[] init 5
> kIndx = 0
> while kIndx < 10 do ;try kIndx < 5 instead
> kArr[kIndx] = 1
> printk2 kIndx
> kIndx += 1
> od
> turnoff
> endin
> 
> 
> csound here looks for the array length and holds kIndx to length-1.
> 
> i would expect that kIndx can increment nevertheless but the internal array index is limited to the maximum of length-1.
> 
> am i wrong?  is this as expe

Date2018-10-03 14:25
Fromjpff
SubjectRe: [Csnd-dev] is this a bug?
I would epect an init error when kIndx is 5 so the instruent would stop. 
What happens?


On Wed, 3 Oct 2018, joachim heintz wrote:

> this code prevents kIndx from increasing more than 5:
>
> instr 1
> kArr[] init 5
> kIndx = 0
> while kIndx < 10 do ;try kIndx < 5 instead
> kArr[kIndx] = 1
> printk2 kIndx
> kIndx += 1
> od
> turnoff
> endin
>
>
> csound here looks for the array length and holds kIndx to length-1.
>
> i would expect that kIndx can increment nevertheless but the internal array 
> index is limited to the maximum of length-1.
>
> am i wrong?  is this as expected?
>
>
> best -
> 	joachim

Date2018-10-03 14:27
Fromjpff
SubjectRe: [Csnd-dev] is this a bug?
Sirry, perf error.


On Wed, 3 Oct 2018, jpff wrote:

> I would epect an init error when kIndx is 5 so the instruent would stop. What 
> happens?
>
>
> On Wed, 3 Oct 2018, joachim heintz wrote:
>
>> this code prevents kIndx from increasing more than 5:
>> 
>> instr 1
>> kArr[] init 5
>> kIndx = 0
>> while kIndx < 10 do ;try kIndx < 5 instead
>> kArr[kIndx] = 1
>> printk2 kIndx
>> kIndx += 1
>> od
>> turnoff
>> endin
>> 
>> 
>> csound here looks for the array length and holds kIndx to length-1.
>> 
>> i would expect that kIndx can increment nevertheless but the internal array 
>> index is limited to the maximum of length-1.
>> 
>> am i wrong?  is this as expected?
>> 
>> 
>> best -
>> 	joachim
>> 

Date2018-10-03 14:33
FromVictor Lazzarini
SubjectRe: [Csnd-dev] is this a bug?
The code returns NOTOK after printing the warning. 
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 3 Oct 2018, at 14:27, jpff  wrote:
> 
> Sirry, perf error.
> 
> 
> On Wed, 3 Oct 2018, jpff wrote:
> 
>> I would epect an init error when kIndx is 5 so the instruent would stop. What happens?
>> 
>> 
>> On Wed, 3 Oct 2018, joachim heintz wrote:
>> 
>>> this code prevents kIndx from increasing more than 5:
>>> instr 1
>>> kArr[] init 5
>>> kIndx = 0
>>> while kIndx < 10 do ;try kIndx < 5 instead
>>> kArr[kIndx] = 1
>>> printk2 kIndx
>>> kIndx += 1
>>> od
>>> turnoff
>>> endin
>>> csound here looks for the array length and holds kIndx to length-1.
>>> i would expect that kIndx can increment nevertheless but the internal array index is limited to the maximum of length-1.
>>> am i wrong?  is this as expected?
>>> best -
>>> 	joachim

Date2018-10-03 14:55
Fromjoachim heintz
SubjectRe: [Csnd-dev] is this a bug?
in my example code, it never reaches the "turnoff" line.



On 03/10/18 15:33, Victor Lazzarini wrote:
> The code returns NOTOK after printing the warning.
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
>> On 3 Oct 2018, at 14:27, jpff  wrote:
>>
>> Sirry, perf error.
>>
>>
>> On Wed, 3 Oct 2018, jpff wrote:
>>
>>> I would epect an init error when kIndx is 5 so the instruent would stop. What happens?
>>>
>>>
>>> On Wed, 3 Oct 2018, joachim heintz wrote:
>>>
>>>> this code prevents kIndx from increasing more than 5:
>>>> instr 1
>>>> kArr[] init 5
>>>> kIndx = 0
>>>> while kIndx < 10 do ;try kIndx < 5 instead
>>>> kArr[kIndx] = 1
>>>> printk2 kIndx
>>>> kIndx += 1
>>>> od
>>>> turnoff
>>>> endin
>>>> csound here looks for the array length and holds kIndx to length-1.
>>>> i would expect that kIndx can increment nevertheless but the internal array index is limited to the maximum of length-1.
>>>> am i wrong?  is this as expected?
>>>> best -
>>>> 	joachim
>>>

Date2018-10-03 15:11
FromVictor Lazzarini
SubjectRe: [Csnd-dev] is this a bug?
It wouldn't. As I said it bails out after the warning is printed and begins again at the top for the next kcycle.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 3 Oct 2018, at 14:55, joachim heintz  wrote:
> 
> in my example code, it never reaches the "turnoff" line.
> 
> 
> 
>> On 03/10/18 15:33, Victor Lazzarini wrote:
>> The code returns NOTOK after printing the warning.
>> ========================
>> Prof. Victor Lazzarini
>> Dean of Arts, Celtic Studies, and Philosophy,
>> Maynooth University,
>> Maynooth, Co Kildare, Ireland
>> Tel: 00 353 7086936
>> Fax: 00 353 1 7086952
>> 
>>> On 3 Oct 2018, at 14:27, jpff  wrote:
>>> 
>>> Sirry, perf error.
>>> 
>>> 
>>>> On Wed, 3 Oct 2018, jpff wrote:
>>>> 
>>>> I would epect an init error when kIndx is 5 so the instruent would stop. What happens?
>>>> 
>>>> 
>>>>> On Wed, 3 Oct 2018, joachim heintz wrote:
>>>>> 
>>>>> this code prevents kIndx from increasing more than 5:
>>>>> instr 1
>>>>> kArr[] init 5
>>>>> kIndx = 0
>>>>> while kIndx < 10 do ;try kIndx < 5 instead
>>>>> kArr[kIndx] = 1
>>>>> printk2 kIndx
>>>>> kIndx += 1
>>>>> od
>>>>> turnoff
>>>>> endin
>>>>> csound here looks for the array length and holds kIndx to length-1.
>>>>> i would expect that kIndx can increment nevertheless but the internal array index is limited to the maximum of length-1.
>>>>> am i wrong?  is this as expected?
>>>>> best -
>>>>>    joachim
>>>> 

Date2018-10-03 16:07
FromMauro Giubileo
SubjectRe: [Csnd-dev] is this a bug?

Personally, in these situations I would prefer that Csound stop the performance with a straightforward error message, instead of jumping the k-cycle and causing many misleading behaviours.

Regards,
Mauro


Il 2018-10-03 15:21 Victor Lazzarini ha scritto:

That's how the code was written. The opcode returns an error code and the rest of the instrument stops executing for
the rest of the k-cycle. Whether that is how it should be or not, I don't know. If we stuck a PerfError() then the instrument
would be stopped. Not sure again if it is too much.

Not signalling is an error might possibly be misleading too.

 
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

On 3 Oct 2018, at 13:18, joachim heintz <jh@joachimheintz.de> wrote:

this code prevents kIndx from increasing more than 5:

instr 1
kArr[] init 5
kIndx = 0
while kIndx < 10 do ;try kIndx < 5 instead
kArr[kIndx] = 1
printk2 kIndx
kIndx += 1
od
turnoff
endin


csound here looks for the array length and holds kIndx to length-1.

i would expect that kIndx can increment nevertheless but the internal array index is limited to the maximum of length-1.

am i wrong?  is this as expected?


best -
    joachim