Gary-Hobson commented on code in PR #8755:
URL: https://github.com/apache/nuttx/pull/8755#discussion_r1133478607


##########
drivers/syslog/ramlog.c:
##########
@@ -267,13 +266,24 @@ static void ramlog_initbuf(void)
 #endif
 
 /****************************************************************************
- * Name: ramlog_addchar
+ * Name: ramlog_addbuf
  ****************************************************************************/
 
-static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
+static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
+                             FAR const char *buffer, size_t len)
 {
+  int readers_waken;
   irqstate_t flags;
-  size_t nexthead;
+  int space;
+  int remain;
+  int head;
+  int ret;
+
+  ret = nxmutex_lock(&priv->rl_lock);

Review Comment:
   You are right, there will be a problem when len>2*rl_bufsize



##########
drivers/syslog/ramlog.c:
##########
@@ -286,84 +296,42 @@ static int ramlog_addchar(FAR struct ramlog_dev_s *priv, 
char ch)
 
   flags = enter_critical_section();
 
-  /* Calculate the write index AFTER the next byte is written */
-
-  nexthead = priv->rl_head + 1;
-  if (nexthead >= priv->rl_bufsize)
-    {
-      nexthead = 0;
-    }
+  /* Calculate the size in the buffer */
 
-  /* Would the next write overflow the circular buffer? */
+  space = (int)priv->rl_head - (int)priv->rl_tail >= 0 ?
+          priv->rl_bufsize - (priv->rl_head - priv->rl_tail) - 1:
+          priv->rl_tail - priv->rl_head - 1;
 
-  if (nexthead == priv->rl_tail)
+  if (len > space)

Review Comment:
   You are right, there will be a problem when len>2*rl_bufsize



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to