mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 21:05:08 +00:00
bhyve/audio.c: avoid re-calculating the length of dev_name
In the function audio_init(), strlen() is being called two times, first to get the length of dev_name and second to use in memcpy(). Creating a local variable and keeping the length avoids this re-calculation. Signed-off-by: rilysh <nightquick@proton.me> Reviewed by: imp, zlei Pull Request: https://github.com/freebsd/freebsd-src/pull/945
This commit is contained in:
parent
2aa186b3b0
commit
8f0498208d
|
@ -80,6 +80,7 @@ audio_init(const char *dev_name, uint8_t dir)
|
|||
#endif
|
||||
};
|
||||
#endif
|
||||
size_t nlen;
|
||||
|
||||
assert(dev_name);
|
||||
|
||||
|
@ -87,8 +88,9 @@ audio_init(const char *dev_name, uint8_t dir)
|
|||
if (!aud)
|
||||
return NULL;
|
||||
|
||||
if (strlen(dev_name) < sizeof(aud->dev_name))
|
||||
memcpy(aud->dev_name, dev_name, strlen(dev_name) + 1);
|
||||
nlen = strlen(dev_name);
|
||||
if (nlen < sizeof(aud->dev_name))
|
||||
memcpy(aud->dev_name, dev_name, nlen + 1);
|
||||
else {
|
||||
DPRINTF("dev_name too big");
|
||||
free(aud);
|
||||
|
|
Loading…
Reference in a new issue