8000 Remove invalid use of `memccpy()` by krader1961 · Pull Request #80 · att/ast · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Remove invalid use of memccpy() #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/lib/libast/sfio/sfputr.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int rc; /* record separator. */

SFLOCK(f,0);

f->val = sn = -1; ss = (char*)s;
f->val = sn = -1; ss = (char*)s;
for(w = 0; (*s || rc >= 0); )
{ /* need to communicate string size to exception handler */
if((f->flags&SF_STRING) && f->next >= f->endb )
Expand Down Expand Up @@ -105,21 +105,15 @@ int rc; /* record separator. */
break;
}

#if _lib_memccpy && !__ia64 && !defined(BSD) /* these guys may never get it right */
/*
* Note that `ps`, and `s` may overlap. So this relies on
* undefined behavior. See issue #42 where it is known to fail
* on MacOS (and presumably other BSD variants).
* Do not replace the following block with `memccpy()`. The
* `ps` and `s` buffers may overlap or even point to the same
* buffer. See issue #42 and #78.
*/
if((ps = (uchar*)memccpy(ps,s,'\0',p)) != NIL(uchar*))
ps -= 1;
else ps = f->next+p;
s += ps - f->next;
#else
for(; p > 0; --p, ++ps, ++s)
if((*ps = *s) == 0)
break;
#endif

w += ps - f->next;
f->next = ps;
}
Expand Down
0