Showcasing a bug

This commit is contained in:
Mike Nolan 2024-09-03 16:35:30 -05:00
parent 9a987fbfa8
commit 3f6189e11f
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
---
title: "A Funny Bug"
date: 2024-09-01T22:51:05-05:00
draft: true
---
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.