- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Mac OS X 上编写了一个小程序,但在以下函数中出现以下错误:
Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000 0x00007fff99b359c4 in strstr ()
/*
* attrvalue(): parse an attribute value pair.
*
* takes a string of the form "ATTRIBUTE = VALUE" and returns the atrribute name
* and value as seperate strings
*
*/
int
attrvalue(char *entry, char **attr, char **value)
{
char *copy;
char *p;
if (!entry || *entry == '\0')
return 1;
copy = strdup(entry);
*attr = strtok(copy, "=");
*value = strtok(NULL, "\n");
/* strip training whitespace from attr and value */
p = strstr(*attr, " ");
if(p)
*p = '\0';
p = strstr(*value, " ");
if(p)
*p = '\0';
return (0);
}
知道这个函数有什么问题吗?
谢谢。
最佳答案
修改后的答案:如果你假设在 attr 或 value 的开头没有空格(即行的开头和 attr 字符串之间,或者等号和 value 字符串之间没有空格),那么你的程序可以只需稍作调整即可工作:将 strstr() 的第二个参数中的多个空格更改为单个空格。带有用于演示的 main() 的修订代码如下。如果您希望去除非尾随空格,那么,当您扩展问题或从下面我的原始答案中的链接借用时,它可能会返回调试器。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
* attrvalue(): parse an attribute value pair.
*
* takes a string of the form "ATTRIBUTE = VALUE" and returns the atrribute name
* and value as seperate strings
*
*/
int
attrvalue(char *entry, char **attr, char **value)
{
char *copy;
char *p;
if (!entry || *entry == '\0')
return 1;
copy = strdup(entry);
*attr = strtok(copy, "=");
*value = strtok(NULL, "\n");
/* strip trailing whitespace from attr and value */
p = strstr(*attr, " ");
if(p)
*p = '\0';
p = strstr(*value, " ");
if(p)
*p = '\0';
return (0);
}
int main()
{
char *input = "asdf =blah "; // this works
//char *input = " asdf = blah"; // this would not
char *attr;
char *value;
attrvalue(input, &attr, &value);
printf("attr =\"%s\"", attr);
printf("value=\"%s\"", value);
return 0;
}
原回答:我会使用一种不同的方法来去除空格,因为它甚至不太清楚 strstr() 在这种情况下如何工作。这是 strstr() documentation , 这是一个 SO topic discussing the removal of whitespace in C .
结合其他想法:
if(p)
应该是 if(p != NULL)
,作为 nit。关于c - 错误 : KERN_INVALID_ADDRESS at address: 0x0000000000000000 0x00007fff99b359c4 in strstr (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14802359/
我不确定为什么会收到此错误,而且我无法查明原因。虽然这只发生在设备上,但模拟器按预期运行无错误。谁能理解这个崩溃日志? Exception Type: EXC_BAD_ACCESS (SIGSEGV
我经常崩溃,你能帮我找出解决办法吗 Incident Identifier: BC2870F3-4119-462B-9B2E-2236E403E7C2 CrashReporter Key: 7d9
我在尝试运行调试器时不断收到此错误: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INV
我有时会遇到这个错误: Thread : Crashed: com.apple.root.default-priority 0 libobjc.A.dylib 0x00
谁能告诉我如何解决我的应用程序中出现的崩溃。我无法找到为什么会发生这次崩溃。我没有得到任何线索。我搜索我的项目以找到“objectIsKindOfClass”,但我没有使用过这种方法。 最佳答案 为了
所以与此类似recently posted question ,我在将 Amazon 的 AWS Obj-C 库与我的 Swift 应用程序集成时遇到问题。我有一个 NSOperation,它使用 T
我有一个奇怪的问题。我收到一个错误报告,说该应用程序崩溃与方向更改有关。问题是我还没有在应用程序代码中注册任何定向事件。我唯一与方向变化有关的是: - (BOOL)shouldAutorotateTo
我在发布的应用程序中偶尔会发生崩溃,并且从崩溃报告中知道它发生的行和崩溃类型 - EXC_BAD_ACCESS (SIGSEGV) KERN_INVALID_ADDRESS - 但我不知道内存如何变得
使用 Crashlytics,我看到我的一小部分用户因错误 EXC_BAD_ACCESS KERN_INVALID_ADDRESS 而崩溃,在以下行中: [[UIApplication sharedA
我正在用 c 语言编写一个程序,该程序严重依赖于正则表达式,我执行它们的机制在 99% 的时间都有效,但它每隔一段时间就会让程序崩溃,我很困惑为什么会这样。 New_Sifter() 采用其正则表达式
我收到这个错误,这可能是什么??? 程序收到信号 EXC_BAD_ACCESS,无法访问内存。原因:KERN_INVALID_ADDRESS 地址:0x0000000000000000strlen (
我看到类方法的 EXC_BAD_ACCESS KERN_INVALID_ADDRESS。 据我所知,我不应该在类/静态方法中看到这一点。 我错过了什么吗? 堆栈跟踪: Thread : Crashed
我使用 Xcode 6.3.2 开发了一个 iPad 应用程序。我将我的应用程序提交到 App Store 进行审核,但由于崩溃而被拒绝。以下是来自 iTunes 的崩溃报告。 Incident Id
我的应用程序通过 Xcode 在 Debug模式下运行良好,但每当通过 TestFlight 下载时,它就会崩溃并出现以下错误:EXC_BAD_ACCESS KERN_INVALID_ADDRESS
MyApp 在 98% 的情况下运行良好,但有时会崩溃。太随意了。 崩溃报告显示以下内容。 Thread : Crashed: com.apple.main-thread 0 libobjc.A.d
iPhone 操作系统上的 KERN_INVALID_ADDRESS 和 KERN_PROTECTION_FAILURE 有什么区别? 我有两个来自临时 Beta 测试人员的崩溃报告,它们相隔 5 分
我不断通过 Crashlytics 收到有关此崩溃的报告,但我不知道如何找出问题所在,因为堆栈跟踪不会在任何地方触及我的代码。我能做些什么?如何找到问题的根源? EXC_BAD_ACCESS KERN
我在 Unity (2019.2.16f1) 上开发了一个游戏,我有一个 大问题 : 1 秒后提交到 App Store 的构建崩溃(启动时) 更多信息: 我编写了一些 c# 脚本,但大部分游戏都使用
我正在尝试将图像更改为黑白,这些图像是从服务调用中提供的,一旦获得图像,我就会应用黑色滤镜将它们更改为黑白。我只在 iOS 13 上遇到过这个悬空指针异常,其他 iOS 版本没有这个问题。 这是代码:
我收到以下错误。 EXC_BAD_ACCESS KERN_INVALID_ADDRESS [UITextField keyboardInputChangedSelection:] 直到这份最新的崩溃
我是一名优秀的程序员,十分优秀!