hugo-site/content/posts/a-funny-bug.md

30 lines
920 B
Markdown
Raw Permalink Normal View History

2024-09-03 21:35:30 +00:00
---
title: "A Funny Bug"
date: 2024-09-01T22:51:05-05:00
2024-09-03 21:51:28 +00:00
draft: false
2024-09-03 21:35:30 +00:00
---
Well I just found a funny bug in one of my upcoming programming projects
```c++
size_t len = (bytecode[ip++] << 24) & 0xFF;
len |= (bytecode[ip++] << 16) & 0xFF;
len |= (bytecode[ip++] << 8) & 0xFF;
len |= bytecode[ip++] & 0xFF;
```
when it was supposed to be
```c++
size_t len = ((size_t)bytecode[ip++] << 24);
len |= ((size_t)bytecode[ip++] << 16);
len |= ((size_t)bytecode[ip++] << 8);
len |= (size_t)bytecode[ip++];
```
this caused all numbers >255 being mod by 255 and I thought my foreach (called each in my languages) implementation was broken
but then I was realizing it was jumping to a number too low for some reason ~20 or something when it should of been ~276
I guess, just be careful when bitshifting and don't be an idiot like me
we all make mistakes.