-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
31 lines (22 loc) · 1.37 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
strxcpy---More Consistent, Safer String Copying and Concatenation
Copyright (c) 2009, 2010 Likai Liu <liulk@cs.bu.edu>
https://code.google.com/p/strxcpy/
The C language makes it easy to write programs with buffer overflow
problems, but there is still something the library can do to help the
programmer make fewer mistakes. For this reason, we propose strxcpy(),
a variant of strcpy() and strcat(), which combines both string copying
and concatenation.
char *strxcpy(char *dest, const char *dest_end, const char *src, size_t n);
The function takes two parameters to define the buffer, dest and
dest_end. It guarantees that it will not overwrite the memory location
past dest_end, and the string at dest is always NUL
terminated. Furthermore, it does not require dest to be a NUL
terminated string. The return value is a character pointer to the NUL
terminator of the dest string, so that we can easily append another
string to it by calling strxcpy() again.
We also propose the sprintf() variants using the same idiom.
char *vsxprintf(char *dest, const char *dest_end, const char *fmt, va_list ap);
char *sxprintf(char *dest, const char *dest_end, const char *fmt, ...);
See this blog post [1] for the motivation of buffer overflow problems.
[1] http://lifecs.likai.org/2010/06/strxcpymore-consistent-safer-string.html
Additional documentation can be found inside the header file stringx.h.