Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.write_encoded_rune only returns \x0 for 0 to 6, 14 & 15 #4609

Open
blob1807 opened this issue Dec 22, 2024 · 0 comments · May be fixed by #4610
Open

io.write_encoded_rune only returns \x0 for 0 to 6, 14 & 15 #4609

blob1807 opened this issue Dec 22, 2024 · 0 comments · May be fixed by #4610

Comments

@blob1807
Copy link
Contributor

blob1807 commented Dec 22, 2024

Context

Odin:    dev-2024-12-nightly:cf53404
OS:      Windows 10 Home Basic (version: 22H2), build 19045.5247
CPU:     AMD Ryzen 9 5900X 12-Core Processor
RAM:     32713 MiB
Backend: LLVM 18.1.8

Expected Behavior

Values 0 to 6, 14 & 15 should be encoded as \x00 to \x06, \x0E & \x0F

Current Behavior

write_encoded_rune only writes \x0 as it doesn't write the string returned from strconv.append_bits

Odin/core/io/util.odin

Lines 132 to 138 in 597fba7

buf: [2]byte
s := strconv.append_bits(buf[:], u64(r), 16, true, 64, strconv.digits, nil)
switch len(s) {
case 0: write_string(w, "00", &n) or_return
case 1: write_byte(w, '0', &n) or_return
case 2: write_string(w, s, &n) or_return
}

Adding fallthrough to case 1 will fix the issue. Don't know if it's worth me making a PR for a small change like this.

Steps to Reproduce

package buggie

import "core:io"
import "core:fmt"
import "core:strings"

main :: proc() {
    sb := strings.builder_make()
    writer := strings.to_writer(&sb)

    for i in '\x00'..='\x10' {
        io.write_encoded_rune(writer, rune(i))
        strings.write_bytes(&sb, {' '})
    }

    fmt.println(string(sb.buf[:]))
    //  current -> '\x0' '\x0' '\x0' '\x0' '\x0' '\x0' '\x0' '\a' '\b' '\t' '\n' '\v' '\f' '\r' '\x0' '\x0' '\x10'
    // expected -> '\x00' '\x01' '\x02' '\x03' '\x04' '\x05' '\x06' '\a' '\b' '\t' '\n' '\v' '\f' '\r' '\x0e' '\x0f' '\x10'
}
@blob1807 blob1807 linked a pull request Dec 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant