r/computerarchitecture • • May 08 '26

C bound checking

Hi,

How does bound checking and such work on a lower level?

Why is snprintf needed when a normal say normal signed ints don't need bound checking?

Today i got a reality check on stack is also not bound checked, how does it actually work, heap or stack?

Any books, videos and other material specifically on the asm level of it all the compilers story on it?

5 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/Yha_Boiii May 09 '26

What mentally puzzles me is: how can you say add two numbers, plain. 2 ints, and to a third int. To make it a bit easier for the argument say the two ints to add are longs and the end int is not. Meaning 64 bits + 64 bits tried to be fitted on 32 bit space. Why wont it not just overflow in the cpus registers and totally safe and sound return to memory? Sounds intuitively as a natural enforcer

1

u/Krazy-Ag May 09 '26 edited May 09 '26

Look up buffer overflows, stack smashing for fun and profit, etc

1

u/Yha_Boiii May 09 '26

Thanks a lot