odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.4k stars 562 forks source link

os.read requires 4 bytes free to read 1 byte #1556

Closed LillyProgrammingIncorprated closed 2 years ago

LillyProgrammingIncorprated commented 2 years ago

Context

I wanted to read input, as you can do with any programming language and do in most programs.

System info: Operating System & Odin Version: Windows 10 Enterprise (version 21H2), Latest nightly build as of 25/02/2022

Expected Behavior

It was supposed to read n number of bytes since I have a slice with n bytes allocated and free.

Current Behavior

It only reads 1 byte for every 4 bytes free on the slice

Failure Information (for bugs)

It only reads 1 byte per 4 bytes available, reducing the available space down to len // 4

Steps to Reproduce

  1. Get Odin on Windows 10
  2. using make, allocated an u8 slice which is divisible by 4 in length ex. 16 (any length works, divisible by 4 only makes it easier to read)
  3. do "x, y := os.read(os.stdin, buffer)"
  4. "fmt.println(x)" at the end to print the bytes read
  5. input the amount of bytes you allocated (16 here)
  6. Observe that it only inputs 4 characters despite having space available for 16

Example Code which reproduces the problem:

package main

import "core:os"
import "core:mem"
import "core:fmt"

main :: proc () {
  test := make([]u8, 16)
  x, y := os.read(os.stdin, test)
  fmt.println(x)
}

EDIT: Edited the steps to be more clear

ftphikari commented 2 years ago

With the latest nightly build passing a buffer of size 16 and inputting 14 characters does not end the input.