Donny9 commented on code in PR #6666:
URL: https://github.com/apache/incubator-nuttx/pull/6666#discussion_r929495381


##########
libs/libc/wchar/lib_wcsnrtombs.c:
##########
@@ -72,50 +67,57 @@
 size_t wcsnrtombs(FAR char *dst, FAR const wchar_t **src, size_t nwc,
                   size_t len, FAR mbstate_t *ps)
 {
-  size_t i;
+  FAR const wchar_t *ws = *src;
+  size_t cnt = 0;
 
   if (dst == NULL)
     {
-      for (i = 0; i < nwc; i++)
+      len = 0;
+    }
+
+  while (ws != NULL && nwc != 0)
+    {
+      char tmp[MB_LEN_MAX];
+      size_t l;
+
+      if (*ws == 0)
         {
-          wchar_t wc = (*src)[i];
+          ws = NULL;
+          break;
+        }
 
-          if (wc < 0 || wc > 0xff)
-            {
-              set_errno(EILSEQ);
-              return -1;
-            }
+      l = wcrtomb(len < MB_LEN_MAX ? tmp : dst, *ws, ps);
+      if ((ssize_t)l < 0)

Review Comment:
   > Posting a comment here just to ensure that `0` is handled properly. It is 
hard to track `l == 0` path
   
   if l == 0, dst also will be NULL, this loop(at line 36) will finish until ws 
== NULL or nwc == NULL. According to spec:
   ```
   If dest is NULL, len is ignored, and the conversion proceeds as above, 
except that the converted bytes are not written out to memory, and that no 
destination length limit exists.
   ```



-- 
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