top | item 27013268

(no title)

sherincall | 4 years ago

The memcpy API says that is Undefined Behavior, that program was never valid. Not much different from bitbanging specific virtual addresses and expecting they never change.

For overlapping memory, use memmove()

discuss

order

aidenn0|4 years ago

Yes, the program was invalid, but it was also accidentally bug free. The two are not mutually exclusive.

dooglius|4 years ago

It was never valid taking in a generic shared interface to libc, but a statically linked version would have been valid.

sherincall|4 years ago

C language makes a difference between Undefined Behavior and Implementation Defined Behavior. In this case it's the former (n1570 section 7.24.2.1).

Any code that invokes UB is not a valid C program, regardless of implemention.

More practically, ignoring the bug that did happen, libc also has multiple implementations of these functions and picks one based on HW it is running on. So even a statically linked glibc could behave differently on different HW. Always read the docs, this is well defined in the standard.