c - 如何为此方法格式化字符串?
问题描述
我在尝试使此方法起作用时遇到问题,我正在尝试将 mbedtls 与 psk 一起使用。事实证明,对于像我这样的 C 新手来说,他们的例子很难理解。
/*
* Parse a string of pairs name1,key1[,name2,key2[,...]]
* into a usable psk_entry list.
*
* Modifies the input string! This is not production quality!
*/
psk_entry * psk_parse( char * psk_string )
{
psk_entry *cur = NULL, *new = NULL;
char *p = psk_string;
char *end = p;
char *key_hex;
while( *end != '\n' )
{
end++;
}
*end = ',';
while( p <= end )
{
if( ( new = mbedtls_calloc( 1, sizeof( psk_entry ) ) ) == NULL )
goto error;
memset( new, 0, sizeof( psk_entry ) );
GET_ITEM( new->name );
GET_ITEM( key_hex );
if( unhexify( new->key, key_hex, &new->key_len ) != 0 )
{
goto error;
}
new->next = cur;
cur = new;
}
return( cur );
error:
psk_free( new );
psk_free( cur );
return( 0 );
}
使此方法起作用的预期字符串格式是什么?目前,我有
char * list = "JD,4f07d80fde6469fbdbf1f154a47f27c916dba68b644ff1ffa26295e598855810";
*end = ','
它被传递给该方法,但是在尝试添加时我不断收到段错误。
解决方案
推荐阅读
- cypress - 在 Cypress 中针对不同来源的两次测试运行之间共享数据的方法
- r - 如何安装许多 R 包?
- powerbi - PowerBI DAX – 同一张表的子查询
- python - 无法使用 virtualenv 或 pipenv 创建虚拟环境
- javascript - 如何使用异步制作自己的等待功能
- java - Spring Data MongoDB 看不到来自父类的私有字段的访问器
- c# - 样式 aspx 导航菜单与悬停时的子菜单
- kdb - KDB 查询返回更多 2 列而不是 1 用于最大过滤器
- javascript - 带有大量内容的 jQuery 工具提示
- javascript - 防止在 JavaScript 中冒泡和捕获事件触发