cederom commented on code in PR #3110:
URL: https://github.com/apache/nuttx-apps/pull/3110#discussion_r2167521330


##########
system/settings/settings.c:
##########
@@ -1114,26 +1098,18 @@ int settings_create(FAR char *key, enum settings_type_e 
type, ...)
   FAR setting_t *setting = NULL;
   int j;
 
-  if (!g_settings.initialized)
-    {
-      assert(0);
-    }
-
-  assert(type != SETTING_EMPTY);
+  assert(g_settings.initialized);
 
-  assert(strlen(key));
-  if (strlen(key) == 0)
+  if (type == SETTING_EMPTY)
     {
       return -EINVAL;
     }
 
-  assert(strlen(key) < CONFIG_SYSTEM_SETTINGS_KEY_SIZE);
-  if (strlen(key) >= CONFIG_SYSTEM_SETTINGS_KEY_SIZE)
+  if (strlen(key) == 0 || strlen(key) >= CONFIG_SYSTEM_SETTINGS_KEY_SIZE)

Review Comment:
   Looking at Kconfig descriptions says its the "maximum size" of key or value 
so it is okay to leave name untouched and avoid possible configuration breaks 
:-)
   
   
https://github.com/apache/nuttx-apps/blob/c4ff19a7e447dec2cdb188415650c5b0e2df9d9c/system/settings/Kconfig#L23-L27
   
   
https://github.com/apache/nuttx-apps/blob/c4ff19a7e447dec2cdb188415650c5b0e2df9d9c/system/settings/Kconfig#L29-L33
   
   Looking again at the code, first assert triggered when `len(key)` was larger 
than `KEY_SIZE`, and later check returns error when len is larger equal than 
`KEY_SIZE`. Because `KEY_SIZE` may be shorter all is okay, thanks for the info, 
lets keep it that way! :-)
   
   ```
   assert(strlen(key) < CONFIG_SYSTEM_SETTINGS_KEY_SIZE);
   if (strlen(key) >= CONFIG_SYSTEM_SETTINGS_KEY_SIZE)
       {
         return -EINVAL;
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to