You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "pkarashchenko (via GitHub)" <gi...@apache.org> on 2023/04/20 11:34:54 UTC

[GitHub] [nuttx-apps] pkarashchenko commented on a diff in pull request #1713: Fixes in asprintf usage.

pkarashchenko commented on code in PR #1713:
URL: https://github.com/apache/nuttx-apps/pull/1713#discussion_r1172450737


##########
graphics/twm4nx/src/cresize.cxx:
##########
@@ -424,8 +426,8 @@ void CResize::updateSizeLabel(FAR struct nxgl_size_s &windowSize)
     }
 
   FAR char *str;
-  asprintf(&str, " %4d x %-4d ", windowSize.w, windowSize.h);
-  if (str == (FAR char *)0)
+  ret = asprintf(&str, " %4d x %-4d ", windowSize.w, windowSize.h);
+  if (ret < 0 || str == (FAR char *)0)

Review Comment:
   ```suggestion
     if (ret < 0)
   ```



##########
netutils/ftpc/ftpc_transfer.c:
##########
@@ -264,7 +267,10 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
 
   else if (strncmp(relpath, "./", 2) == 0)
     {
-      asprintf(&ptr, "%s%s", curdir, relpath + 1);
+      if (asprintf(&ptr, "%s%s", curdir, relpath + 1) < 0)
+        {
+          ptr = NULL;

Review Comment:
   why this is needed?



##########
graphics/twm4nx/src/ctwm4nx.cxx:
##########
@@ -382,7 +382,10 @@ void CTwm4Nx::genMqName(void)
   unsigned long randvalue =
     (unsigned long)std::random() & 0x00fffffful;
 
-  std::asprintf(&m_queueName, "Twm4Nx%06lu", randvalue);
+  if (std::asprintf(&m_queueName, "Twm4Nx%06lu", randvalue) < 0)
+    {
+      m_queueName = NULL;

Review Comment:
   why this is needed?



##########
netutils/ftpc/ftpc_transfer.c:
##########
@@ -247,7 +247,10 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
 
       else if (relpath[1] == '/')
         {
-          asprintf(&ptr, "%s%s", homedir, &relpath[1]);
+          if (asprintf(&ptr, "%s%s", homedir, &relpath[1]) < 0)
+            {
+              ptr = NULL;

Review Comment:
   why this is needed?



##########
system/critmon/critmon.c:
##########
@@ -136,11 +135,9 @@ static int critmon_process_directory(FAR struct dirent *entryp)
                  entryp->d_name);
   if (ret < 0 || filepath == NULL)
     {
-      errcode = errno;
       fprintf(stderr,
-              "Csection Monitor: Failed to create path to status file: %d\n",
-              errcode);
-      return -errcode;
+              "Csection Monitor: Failed to create path to status file\n");

Review Comment:
   Maybe remove `filepath == NULL` from check above?



##########
system/critmon/critmon.c:
##########
@@ -326,10 +321,8 @@ static void critmon_global_crit(void)
                  CONFIG_SYSTEM_CRITMONITOR_MOUNTPOINT "/critmon");
   if (ret < 0 || filepath == NULL)
     {
-      errcode = errno;
       fprintf(stderr, "Csection Monitor: "
-              "Failed to create path to Csection file: %d\n",
-              errcode);
+              "Failed to create path to Csection file\n");

Review Comment:
   Maybe remove `filepath == NULL` from check above?



##########
system/critmon/critmon.c:
##########
@@ -189,10 +186,8 @@ static int critmon_process_directory(FAR struct dirent *entryp)
                  entryp->d_name);
   if (ret < 0 || filepath == NULL)
     {
-      errcode = errno;
       fprintf(stderr, "Csection Monitor: "
-              "Failed to create path to Csection file: %d\n",
-              errcode);
+              "Failed to create path to Csection file\n");

Review Comment:
   Maybe remove `filepath == NULL` from check above?



##########
system/stackmonitor/stackmonitor.c:
##########
@@ -191,10 +188,8 @@ static int stkmon_process_directory(FAR struct dirent *entryp)
                  entryp->d_name);
   if (ret < 0 || filepath == NULL)
     {
-      errcode = errno;
       fprintf(stderr,
-              "Stack Monitor: Failed to create path to stack file: %d\n",
-              errcode);
+              "Stack Monitor: Failed to create path to stack file\n");

Review Comment:
   Maybe remove `filepath == NULL` from check above?



##########
netutils/ftpc/ftpc_transfer.c:
##########
@@ -278,7 +284,10 @@ static FAR char *ftpc_abspath(FAR struct ftpc_session_s *session,
 
   else
     {
-      asprintf(&ptr, "%s/%s", curdir, relpath);
+      if (asprintf(&ptr, "%s/%s", curdir, relpath) < 0)
+        {
+          ptr = NULL;

Review Comment:
   why this is needed?



##########
system/stackmonitor/stackmonitor.c:
##########
@@ -136,11 +135,9 @@ static int stkmon_process_directory(FAR struct dirent *entryp)
                  entryp->d_name);
   if (ret < 0 || filepath == NULL)
     {
-      errcode = errno;
       fprintf(stderr,
-              "Stack Monitor: Failed to create path to status file: %d\n",
-              errcode);
-      return -errcode;
+              "Stack Monitor: Failed to create path to status file\n");

Review Comment:
   Maybe remove `filepath == NULL` from check above?



-- 
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-unsubscribe@nuttx.apache.org

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