mirror of
https://git.proxmox.com/git/mirror_corosync
synced 2025-08-03 12:05:09 +00:00
logsys.c: avoid redundant strlen in else-block
* exec/logsys.c (strcpy_cutoff): Also, with a field width (aka cutoff), and a shorter-than-field-width string, don't write the same memory twice: once with strncpy using NUL bytes, then again with spaces via the memset. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2177 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
parent
fbbc934196
commit
d04702854b
@ -65,6 +65,8 @@
|
||||
|
||||
#define YIELD_AFTER_LOG_OPS 10
|
||||
|
||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
/*
|
||||
* similar to syslog facilities/priorities tables,
|
||||
* make a tag table for internal use
|
||||
@ -381,18 +383,15 @@ do { \
|
||||
*/
|
||||
static inline int strcpy_cutoff (char *dest, const char *src, int cutoff)
|
||||
{
|
||||
size_t len = strlen (src);
|
||||
if (cutoff <= 0) {
|
||||
size_t len = strlen (src);
|
||||
memcpy (dest, src, len + 1);
|
||||
return (len);
|
||||
} else {
|
||||
size_t len;
|
||||
strncpy (dest, src, cutoff);
|
||||
len = MIN (len, cutoff);
|
||||
memcpy (dest, src, len);
|
||||
memset (dest + len, ' ', cutoff - len);
|
||||
dest[cutoff] = '\0';
|
||||
len = strlen (dest);
|
||||
if (len != cutoff) {
|
||||
memset (&dest[len], ' ', cutoff - len);
|
||||
}
|
||||
}
|
||||
return (cutoff);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user