mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Add NULL termination to tune string and fix missing break
This commit is contained in:
committed by
Gregory Nutt
parent
ead4b6014e
commit
229a200734
+13
-1
@@ -495,6 +495,7 @@ static void next_note(FAR struct tone_upperhalf_s *upper)
|
||||
|
||||
case 'B':
|
||||
g_repeat = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
auderr("unknown symbol: %c!\n", c);
|
||||
@@ -863,9 +864,9 @@ static ssize_t tone_read(FAR struct file *filep, FAR char *buffer,
|
||||
static ssize_t tone_write(FAR struct file *filep, FAR const char *buffer,
|
||||
size_t buflen)
|
||||
{
|
||||
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct tone_upperhalf_s *upper = inode->i_private;
|
||||
int ndx;
|
||||
|
||||
/* We need to receive a string #RRGGBB = 7 bytes */
|
||||
|
||||
@@ -876,10 +877,21 @@ static ssize_t tone_write(FAR struct file *filep, FAR const char *buffer,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (buflen >= MAX_TUNE_LEN)
|
||||
{
|
||||
/* Too big to it inside internal buffer (with extra NUL terminator) */
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Copy music to internal buffer */
|
||||
|
||||
memcpy(tune_buf, buffer, buflen);
|
||||
|
||||
/* Failsafe NUL terminated string */
|
||||
|
||||
tune_buf[buflen] = '\0';
|
||||
|
||||
/* Let the music play */
|
||||
|
||||
start_tune(upper, tune_buf);
|
||||
|
||||
Reference in New Issue
Block a user