I have a strange problem with Nim (both 19.2 release and 19.9[most current] 
nightly.
    
    
    const MEG64 = 1024 * 1024 * 64
    var somebuf: array[MEG64, char]  # some large buffer
    # ...
    proc char_arr_stuff(bufx: openArray[char], start: int) =
       var
           j = 0
           c: char
       while j < 64:
          let k = start + j
          debugEcho "j, k: " & $j & ", " & $k # first output: "0, 0" (as 
expected)
          c = bufx[k] # BANG!
    # ...
    # open a file with (a bit more than) 64MB data (all in a..z,A..Z,0..9)
    let bytesRead = myfile.readData(addr(somebuf[0]),  MEG64) # Note: This 
works.
    # ...
    
    Run

with `char_arr_stuff` getting passed in `somebuf`.

Nim compiles OK but when running it it raises "index 0 not in 0 .. -1 
[IndexError]" through `raiseIndexError2`.

Well noted, the file reading works and `somebuf` (as well as `bufx` which is 
just `somebuf` passed into the proc) is valid and does contain (the correct) 
data. So 0 is not within `0 .. -1`?? Side note: To be really, really sure I 
verified that `bufx.low() == 0`.

Btw @dom96

It drives me nuts that I always have to indent by hand code I insert here. 
Probably it's just me being forum-stupid. Would you please tell me how to do it 
better?

Reply via email to