This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
     new a350469  cmd/os_mgmt: remove VLA usage in datetime command
a350469 is described below

commit a35046916b6e1bfcd89ab5c4904348e9ab551c72
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Mon Oct 6 10:01:24 2025 +0200

    cmd/os_mgmt: remove VLA usage in datetime command
    
    Build failed with GCC 9-2020-q2 and GCC 10.3-2021.10 because of
    the VLA warning in `os_mgmt_impl_datetime_info`. This PR fixes this
    issue implemented in #181 by removing the variable length array.
---
 cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c 
b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
index 77abfb8..9e8b188 100644
--- a/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
+++ b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
@@ -101,27 +101,24 @@ os_mgmt_impl_task_info(int idx, struct os_mgmt_task_info 
*out_info)
 int
 os_mgmt_impl_datetime_info(char *datetime, size_t size)
 {
+    struct os_timeval tv;
+    struct os_timezone tz;
+    int rc;
+
     if (size < DATETIME_BUFSIZE) {
         return MGMT_ERR_ENOMEM;
     }
 
-    struct os_timeval tv;
-    struct os_timezone tz;
-    char buf[size];
-    int rc = 0;
-
     rc = os_gettimeofday(&tv, &tz);
     if (rc != 0) {
         return MGMT_ERR_EINVAL;
     }
 
-    rc = datetime_format(&tv, &tz, buf, sizeof(buf));
+    rc = datetime_format(&tv, &tz, datetime, size);
     if (rc != 0) {
         return MGMT_ERR_EINVAL;
     }
 
-    snprintf(datetime, size, "%s", buf);
-
     return MGMT_ERR_EOK;
 }
 

Reply via email to