8000 overlapping buffers and `memccpy()` · Issue #78 · att/ast · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
overlapping buffers and memccpy() #78
Closed
@krader1961

Description

@krader1961

The change I authored, commit de00119, which was recently merged to fix building on BSD based systems like macOS only works when using gcc to do the compilation. If you instead use the clang compiler provided by Apple it fails because the BSD preprocessor symbol isn't defined. You also need to blacklist __APPLE__.

But here's the thing, the code before my change began with this preprocessor directive:

#if _lib_memccpy && !__ia64 /* these guys may never get it right */

The problem is that assertion is wrong. It implies that the libc implementation of memccpy() on IA64 is broken. Which is incorrect. The problem is the AST sfputr() function is depending on what is explicitly undefined behavior in the face of overlapping source and destination buffers. Every implementation is free to optimize the operation by assuming the buffers do not overlap but in so doing produce incorrect results, including aborting the program, if the buffers do overlap.

I was too timid with my previous change. I should not have added another blacklisted architecture. Instead the use of memccpy() should simply be removed. If you look at the two alternatives using memccpy() simply complicates the code and is unlikely to be measurably, let alone noticeably, faster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0