Skip to content

stb_ds: fix signed shift overflow in byte hashes - #2024

Closed
txgk wants to merge 1 commit into
nothings:masterfrom
txgk:shift-overflow
Closed

txgk wants to merge 1 commit into
nothings:masterfrom
txgk:shift-overflow

Conversation

@txgk

@txgk txgk commented Oct 23, 2026

Copy link
Copy Markdown

how to reproduce the bug:

#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"
#include <stdint.h>

int main() {
  uint64_t a = 0x0000000080000000;
  size_t ha = stbds_hash_bytes(&a, sizeof(a), 0);
  return ha;
}

when this is compiled with gcc -fsanitize=undefined, program yields:

stb_ds.h:1180:61: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'

the provided patch fixes this undefined behavior

how to reproduce the bug:

```c

int main() {
  uint64_t a = 0x0000000080000000;
  size_t ha = stbds_hash_bytes(&a, sizeof(a), 0);
  return ha;
}
```

when this is compiled with gcc -fsanitize=undefined, program yields:

```
stb_ds.h:1180:61: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'
```

the provided patch fixes this undefined behavior
@nothings

Copy link
Copy Markdown
Owner

duplicate of #1188

@nothings nothings closed this Oct 23, 2026
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 this pull request may close these issues.

2 participants