# After console IO updates input command fails

**URL:** <https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66>\
**Category:** Bugs\
**Tags:** closed\
**Created:** [July 19, 2026, 7:14pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66 "2026-07-19T19:14:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 19, 2026, 7:14pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/1 "2026-07-19T19:14:53Z")

</div>

I built from source the console only version today and Input “How old are you?”, ans fails with this output  
How old are you? 4 malloc(): invalid size (unsorted)  
Aborted  
the cursor waits for an input but jitters like it keeps testing for an input like inkey would. Once I answer and enter I get that error. I just updated to Debian Trixie

---

<div class="post-metadata">

**Author:** ![chrisws](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chrisws](https://smallbasic.discourse.group/u/chrisws)\
**Post date:** [July 20, 2026, 3:49am UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/2 "2026-07-20T03:49:35Z")

</div>

Hi Barry,

Could you please give the exact steps and program you tried?

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 20, 2026, 12:25pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/3 "2026-07-20T12:25:09Z")

</div>

I was shy about reporting this because it seemed to obvious to get released.  
```  
#!/usr/local/bin/sbasic

input "How old are you? ", ans

print ans  
```

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 20, 2026, 1:20pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/4 "2026-07-20T13:20:07Z")

</div>

I sent a email over to [smallbasic@gmail.com](mailto:smallbasic@gmail.com) with debugging info if that helps.

---

<div class="post-metadata">

**Author:** ![J7M](https://yyz2.discourse-cdn.com/free1/user_avatar/smallbasic.discourse.group/j7m/32/7_2.png) [@J7M](https://smallbasic.discourse.group/u/J7M)\
**Post date:** [July 20, 2026, 7:34pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/5 "2026-07-20T19:34:27Z")

</div>

I tried your program on a Windows laptop and my Manjaro desktop. I could not reproduce it. The program you posted works fine. `malloc(): invalid size (unsorted)` indicates, that an element of an array was accessed that was not allocated by `malloc()`. I have to debug a little bit.

---

<div class="post-metadata">

**Author:** ![chrisws](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chrisws](https://smallbasic.discourse.group/u/chrisws)\
**Post date:** [July 20, 2026, 11:03pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/6 "2026-07-20T23:03:44Z")

</div>

> [@BarrySWTP](#):
>
> #!/usr/local/bin/sbasic
> 
> input "How old are you? ", ans
> 
> print ans

It’s related to src/platform/console/input\_history.h  
Try this change and run it again

void push(const char \*input) {  
std::string new\_entry;  
try {  
new\_entry = std::string(input);  
} catch (const std::exception& e) {  
fprintf(stderr, “\nCaught exception in push() %s\n”, e.what() );  
return;  
}  
history\_stack.push\_back(new\_entry);  
current\_index = ((int)history\_stack.size());  
}

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 21, 2026, 12:24am UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/7 "2026-07-21T00:24:31Z")

</div>

Unfortunately after the input\_history.h modification I received the same result / error. I put it back like it was.  
I knew it was working on x86 systems so I talked to AI about the differences and compiler flags fixed it. Copied from AI:  
When C/C++ code works fine on x86/x86\_64 (Linux & Windows) but crashes with heap corruption on ARM64 (like your Debian Trixie container on Chromebook), the suspect is almost always char sign signedness.

The Architecture Catch  
On x86 / x86\_64: char is signed by default in GCC (-128 to 127).

On ARM / ARM64: char is unsigned by default in GCC (0 to 255).  
On ARM64, if ch is negative (like -1 or -2 returned when no key is pressed or during terminal escape sequences), implicit casts to char\* or calculations in dev\_input\_insert\_char treat values as 255 (0xFF) instead of -1.

That causes strlen((char \*)cstr) or string boundary checks to miscalculate array offsets, reading past the end of strings and overwriting malloc heap headers!  
You don’t need to rewrite all the string logic. You can tell GCC on ARM64 to treat char as signed, matching x86 behavior exactly!  
Reconfigure / rebuild with signed char forced

CXXFLAGS=“-g -O2 -fsigned-char” CFLAGS=“-g -O2 -fsigned-char” ./configure  
End of AI  
I’m still testing but so far everything is working as expected. Sorry for the long post!

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 22, 2026, 6:21pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/8 "2026-07-22T18:21:18Z")

</div>

This wasn’t a good fix, I sent an email with some code changes for your review.

---

<div class="post-metadata">

**Author:** ![J7M](https://yyz2.discourse-cdn.com/free1/user_avatar/smallbasic.discourse.group/j7m/32/7_2.png) [@J7M](https://smallbasic.discourse.group/u/J7M)\
**Post date:** [July 25, 2026, 12:43pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/9 "2026-07-25T12:43:01Z")

</div>

I tested on a Raspberry Pi 3B with Raspberry Pi OS Trixi (64bit). `Input` did not crash but printed nonstop garbage. I realized that `vt100_inputReadKey()` returned 255 when no key was pressed. A fix was to change the following lines in vt100.cpp:

```auto
int getch() {
  char c; --> signed char c
  if (read(STDIN_FILENO, &c, 1) == 1) {
    return (int)c;
  }
  return EOF;
}

uint32_t vt100_inputReadKey(void) {
  char c = getch(); --> signed char c

```

After this changes everything works fine on the Pi so far.

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 25, 2026, 1:45pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/10 "2026-07-25T13:45:55Z")

</div>

After pulling down a fresh vt100.cpp and making your changes everything I’ve tested is working perfectly with one exception. If a program uses XDG-OPEN to open a web page when that browser is closed I still get the ;1R fragment after the console prompt. This edit stopped that from happening, you might know of a better way.

> if (dev\_get\_millisecond\_count() - startTime \> 50) { → 100

Maybe my Chromebook is just slow. Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![J7M](https://yyz2.discourse-cdn.com/free1/user_avatar/smallbasic.discourse.group/j7m/32/7_2.png) [@J7M](https://smallbasic.discourse.group/u/J7M)\
**Post date:** [July 25, 2026, 6:04pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/11 "2026-07-25T18:04:53Z")

</div>

most probably it will be fine to set the timeout to 100ms. I chose the 50ms without much thinking. Can you give me an example program? I would like to see if I also get this quite long timeout.

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 25, 2026, 7:10pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/12 "2026-07-25T19:10:51Z")

</div>

> #!/usr/local/bin/sbasic
> 
> REM SmallBASIC
> 
> REM created: 11/01/2024
> 
> run(“xdg-open ‘[https://radar.weather.gov/ridge/standard/KTBW\_loop.gif](https://radar.weather.gov/ridge/standard/KTBW_loop.gif)’”)

---

<div class="post-metadata">

**Author:** ![J7M](https://yyz2.discourse-cdn.com/free1/user_avatar/smallbasic.discourse.group/j7m/32/7_2.png) [@J7M](https://smallbasic.discourse.group/u/J7M)\
**Post date:** [July 27, 2026, 9:21am UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/13 "2026-07-27T09:21:57Z")

</div>

@BarrySWTP: Chris merged my pull request. The `singed char` fix and increase if the timeout to 100ms are now online. I also added a fix, that INPUT doesn’t use 100% of one core of the CPU anymore. Thank you for reporting the bug.

---

<div class="post-metadata">

**Author:** ![BarrySWTP](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@BarrySWTP](https://smallbasic.discourse.group/u/BarrySWTP)\
**Post date:** [July 27, 2026, 12:22pm UTC](https://smallbasic.discourse.group/t/after-console-io-updates-input-command-fails/66/14 "2026-07-27T12:22:00Z")

</div>

@J7M Joerg, thanks for all your help and quick response.
