/**
* Set an environment variable. If it value is NULL, delete it.
* If not find it in environment variables table, then create it.
*
* @param key environment variable name
* @param value environment variable value
*
* @return result
*/
FlashErrCode flash_set_env(const char *key, const char *value) {
FlashErrCode result = FLASH_NO_ERR;
FLASH_ASSERT(env_cache);
/* if value is null, delete it */
if (*value == NULL) {
result = flash_del_env(key);
} else {
/* if find this variables, then delete it and recreate it */
if (find_env(key)) {
result = flash_del_env(key);
}
if (result == FLASH_NO_ERR) {
result = create_env(key, value);
}
}
return result;
}
应该传入的还是NULL,在setenv中检测到参数个数不够的时候,value都是作为NULL传入
void setenv(uint8_t argc, char **argv) {
uint8_t i;
char c_value = NULL;
char value = &c_value;
if (argc > 3) {
/ environment variable value string together */
for (i = 0; i < argc - 2; i++) {
argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
}
}
if (argc == 1) {
flash_set_env(value, value);
} else if (argc == 2) {
flash_set_env(argv[1], value);
} else {
flash_set_env(argv[1], argv[2]);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
@棋有此理 不知道你对“空字符串”、“空指针”及“NULL”3者如何理解的。
按照注释上写的,key的value为NULL,则删除该环境变量。那么执行flash_set_env("abc",NULL);
,即可删除环境变量"adc"。
空字符: "" 也就是指针指向的内存存放一个字节0x00的数据, 空指针就是指向0地址的指针, NULL 常定义为(void*)0, 也就是空指针,这么理解没错吧,你确定你运行过flash_set_env("abc",NULL);
, 我运行就就死了,对代码中对空指针进行解引用了, if (*value == NULL)
. 但是运行flash_set_env("abc", "");
则就能执行环境变量的删除操作.
note_104402
状态更改为 已关闭
把对value的解引用取消也可以吧,改成if (value == NULL),否则该就不只是注释,前面那些调用flash_set_env的时候,传入的都是NULL
不是的,删除env实际上都是 flash_set_env("abc", "");
这样的方式,是我的名词解释有问题。
登录 后才可以发表评论