mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 16:15:11 +00:00
staging: speakup: Replace strncpy with memcpy
commit fd29edc723
upstream.
gcc 8.1.0 generates the following warnings.
drivers/staging/speakup/kobjects.c: In function 'punc_store':
drivers/staging/speakup/kobjects.c:522:2: warning:
'strncpy' output truncated before terminating nul
copying as many bytes from a string as its length
drivers/staging/speakup/kobjects.c:504:6: note: length computed here
drivers/staging/speakup/kobjects.c: In function 'synth_store':
drivers/staging/speakup/kobjects.c:391:2: warning:
'strncpy' output truncated before terminating nul
copying as many bytes from a string as its length
drivers/staging/speakup/kobjects.c:388:8: note: length computed here
Using strncpy() is indeed less than perfect since the length of data to
be copied has already been determined with strlen(). Replace strncpy()
with memcpy() to address the warning and optimize the code a little.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
5c35dc008c
commit
df62280ba8
1 changed files with 2 additions and 2 deletions
|
@ -387,7 +387,7 @@ static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr,
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
if (len < 2 || len > 9)
|
if (len < 2 || len > 9)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
strncpy(new_synth_name, buf, len);
|
memcpy(new_synth_name, buf, len);
|
||||||
if (new_synth_name[len - 1] == '\n')
|
if (new_synth_name[len - 1] == '\n')
|
||||||
len--;
|
len--;
|
||||||
new_synth_name[len] = '\0';
|
new_synth_name[len] = '\0';
|
||||||
|
@ -517,7 +517,7 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(punc_buf, buf, x);
|
memcpy(punc_buf, buf, x);
|
||||||
|
|
||||||
while (x && punc_buf[x - 1] == '\n')
|
while (x && punc_buf[x - 1] == '\n')
|
||||||
x--;
|
x--;
|
||||||
|
|
Loading…
Reference in a new issue