- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在第 4 行的 process_query_str 中,我调用 splitline 并返回一个包含 3 个元素的字符串数组,最后一个元素为 NULL。该数组是 malloced 的,因此是各个字符串。然后我尝试释放每个元素,然后释放数组本身(在第一个函数的末尾)。前两个字符串被释放,但当它释放第三个元素时,它是 NULL,我在底部收到关于无效指针的错误。显然它没有被设置为 NULL 而应该是。我尝试放置断点,但程序不会停止。
char * process_query_str(char *rq, char *cmd) {
logg("In process_query_str.\n");
int has_query = 0;
char **tokenized_args = splitline(rq, &has_query); //Tokenize the string based on '?'
char * query_str = rq;
logg("has_query:");
fprintf(stderr, "%d", has_query);
if (has_query == 1) //Check for Query String
if (query_str != NULL) {
query_str = retrieve_query_str(tokenized_args);
logg("Query String: ");
logg(query_str);
logg("\n");
char* key = "REQUEST_METHOD"; //Process REQUEST_METHOD envir variable
if (VLstore(key, cmd) == 0)
if (VLexport(key) == 0) {
logg("Successfully exported ");
logg(cmd);
logg(": ");
logg(key);
logg("\n");
key = "QUERY_STRING"; //Process QUERY_STRING envir variable
if (VLstore(key, query_str) != 1) //1 signals a problem
if (VLexport(key) != 0) //0 signals a problem
{
logg("Successfully exported ");
logg(cmd);
logg(": ");
logg(key);
logg("\n");
}
}
}
#ifdef LOGGING //Print out environment variables
VLlist();
#endif
char *resource_str = newstr(tokenized_args[0], strlen(tokenized_args[0]));
freelist(tokenized_args);
logg("resource_str=");
logg(resource_str);
logg("\n");
return resource_str;
}
char ** splitline(char *line, int*has_query)
/*
* purpose: split a line into array of white-space separated tokens
* returns: a NULL-terminated array of pointers to copies of the tokens
* or NULL if line if no tokens on the line
* action: traverse the array, locate strings, make copies
* note: strtok() could work, but we may want to add quotes later
*/
{
//char *newstr();
logg("In splitline\n");
char **args;
int spots = 0; /* spots in table */
int bufspace = 0; /* bytes in table */
int argnum = 0; /* slots used */
char *cp = line; /* pos in string */
char *start;
int len;
if (line == NULL) /* handle special case */
return NULL;
args = emalloc(BUFSIZ); /* initialize array */
bufspace = BUFSIZ;
spots = BUFSIZ / sizeof(char *);
while (*cp != '\0') {
logg("*cp=");
fprintf(stderr, "%c", *cp);
while (*cp == ' ') /* skip leading spaces */
cp++;
if (*cp == '\0') /* quit at end-o-string */
break;
/* make sure the array has room (+1 for NULL) */
if (argnum + 1 >= spots) {
args = erealloc(args, bufspace + BUFSIZ);
bufspace += BUFSIZ;
spots += (BUFSIZ / sizeof(char *));
}
/* mark start, then find end of word */
start = cp;
len = 1;
if (*cp == '?') {
logg("query reached.\n");
*has_query = 1;
}
while (*++cp != '\0' && !(is_delim(*cp,*has_query)))
len++;
args[argnum++] = newstr(start, len);
}
logg("arg[0] =");
logg(args[0]);
logg("\n");
if (argnum == 2) {
logg("arg[1] =");
logg(args[1]);
logg("\n");
}
args[argnum] = NULL;
fprintf(stderr, "last element is NULL. argnum=%d", argnum);
return args;
}
void freelist(char **list)
/*
* purpose: free the list returned by splitline
* returns: nothing
* action: free all strings in list and then free the list
*/
{
char **cp = list;
while (*cp && (*cp)) {
logg("free: ");logg(*cp);logg("\n");
free(*cp++);
}
logg("Now Free the list:");logg("\n");
free(list);
logg("Done Freeing List\n");
}
我从 glibc
得到的堆栈回溯信息是:
free: /index.cgifree: key=value*** glibc detected *** ./ws: free(): invalid pointer: 0x0804efa9 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb76d3d05]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb76d7770]
./ws[0x804b36f]
./ws[0x804a1fb]
./ws[0x8049de1]
./ws[0x8049757]
./ws[0x8049660]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb767e460]
./ws[0x8049031]
======= Memory map: ========
08048000-0804d000 r-xp 00000000 00:24 8084895 /nfs/home/j/c/jcalderon/unixlin ux/wsng/ws
0804d000-0804e000 rw-p 00004000 00:24 8084895 /nfs/home/j/c/jcalderon/unixlin ux/wsng/ws
0804e000-0806f000 rw-p 0804e000 00:00 0 [heap]
b7500000-b7521000 rw-p b7500000 00:00 0
b7521000-b7600000 ---p b7521000 00:00 0
b7644000-b764e000 r-xp 00000000 68:07 1122448 /lib/libgcc_s.so.1
b764e000-b764f000 rw-p 0000a000 68:07 1122448 /lib/libgcc_s.so.1
b765c000-b7665000 r-xp 00000000 68:07 1122335 /lib/tls/i686/cmov/libnss_files -2.7.so
b7665000-b7667000 rw-p 00008000 68:07 1122335 /lib/tls/i686/cmov/libnss_files -2.7.so
b7667000-b7668000 rw-p b7667000 00:00 0
b7668000-b77b2000 r-xp 00000000 68:07 1122611 /lib/tls/i686/cmov/libc-2.7.so
b77b2000-b77b3000 r--p 0014a000 68:07 1122611 /lib/tls/i686/cmov/libc-2.7.so
b77b3000-b77b5000 rw-p 0014b000 68:07 1122611 /lib/tls/i686/cmov/libc-2.7.so
b77b5000-b77b8000 rw-p b77b5000 00:00 0
b77c2000-b77c7000 rw-p b77c2000 00:00 0
b77c7000-b77c8000 r-xp b77c7000 00:00 0 [vdso]
b77c8000-b77e2000 r-xp 00000000 68:07 1124008 /lib/ld-2.7.so
b77e2000-b77e4000 rw-p 00019000 68:07 1124008 /lib/ld-2.7.so
bfd9f000-bfdb4000 rw-p bffea000 00:00 0 [stack]
最佳答案
这不是您问题的答案,但它会帮助您减少代码量。您有以下片段:
logg("Successfully exported ");
logg(cmd);
logg(": ");
logg(key);
logg("\n");
如果你能这样写会更简单:
logg("Successfully exported %s: %s\n", cmd, key);
你可以通过修改这个函数来做到这一点:
#include <stdarg.h>
#include <stdio.h>
void logg(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
您可以在 header 中声明它:
#ifdef __GNUC__
#define PRINTFLIKE(n,m) __attribute__((format(printf,n,m)))
#else
#define PRINTFLIKE(n,m) /* If only */
#endif /* __GNUC__ */
extern void logg(const char *format, ...) PRINTFLIKE(1, 2);
然后 GCC 将发现格式转换规范与传递给函数的参数的滥用。
请注意,此版本的 logg()
基本上与前一个版本调用兼容。唯一会出现差异的情况是,如果正在打印的字符串包含类似 %Z
的字符串,该字符串现在被视为转换规范,而以前不是。不过,您应该使用 logg("%s\n", argument);
或类似的方法。
关于c - 无效指针 : free(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10466819/
我有一个接受以下参数的函数: int setvalue(void (*)(void *)); 为了满足参数:void (*)(void *),我创建了这样一个函数: static void *
我有以下代码: typedef void VOID; int f(void); int g(VOID); 在 C 中编译得很好(在 Fedora 10 上使用 gcc 4.3.2)。与 C++ 编译的
这个问题已经有答案了: Is f(void) deprecated in modern C and C++? [duplicate] (6 个回答) 已关闭 7 年前。 B.A.T.M.A.N./A.
我在 ASP.NET Core 3.1 项目上有以下 Identity Server 4 配置: services .AddIdentityServer(y => { y.Events.R
我们有一个 O365 租户,一切都是开箱即用的。租户放置在德国云中,而不是全局 (office.de) 中。我们还开发了一个 Office 插件,使用 OAuth 2.0 授权访问共享点。首先,我们向
我有一个如下所示的路由 routes.MapRoute( name: "Default", url: "{controller}/{action}/{i
我正在尝试使用 OAuth2.0 访问 google 文档。我已经从 Google API 控制台获取了客户端 ID 和 key 。但是当我运行这段代码时,我收到了异常。如果我遗漏了什么,有人可以建议
此代码有效: let mut b: Vec = Vec::with_capacity(a.len()); for val in a.iter() { b.push(val); } 此代码不起作
使用 client_credintials 授权类型请求 EWS oauth2 v2.0 的访问 token 时出现错误。 https://login.microsoftonline.com/tena
我通过 Java 应用程序使用 Google 电子表格时遇到了问题。我创建了应用程序,该应用程序运行了 1 年多,没有任何问题,我什至在 Create Spreadsheet using Google
如何创建 匹配所有无效 Base64 字符的正则表达式?我在堆栈上找到了 [^a-zA-Z0-9+/=\n\r].*$ 但是当我尝试时我得到了带有 - 符号的结果字符串.我根本不知道正则表达式,任何人
我从 Gitlab CI/CD Pipelines 获得错误信息:yaml invalid。问题是由 .gitlab-ci.yml 脚本的第五行引起的: - 'ssh deployer@gita
我有 3 个数据源,设置如下: @Configuration @Component public class DataSourceConfig { @Bean("foo") @Conf
你好,我想用bulkCreate ex 插入数据: [ { "typeId": 5, "devEui": "0094E796CBFCFEF9", "application_name": "Pressu
UIApplicationExitsOnSuspend 不会强制我的应用程序退出。我已经清理过目标、删除了应用程序、重建并重新安装了很多次。 我确实需要退出我的应用程序。 最佳答案 您是否链接了 SD
在 iPhone 配置门户上,显示我的 iPhone 团队配置配置文件无效。有一个“由 Xcode 管理”文本。 “续订”按钮被禁用。 我该如何解决这个问题?谢谢 最佳答案 使用 Xcode 3.2.
好的,所以今天我用我们的“实时”数据库中的新信息更新了我的数据库……从那时起,我的一个表格就出现了问题。如果您需要任何代码,请告诉我,我将对其进行编辑并发布所需的代码... 我有一个报告表格,其中有一
我有一个结构体,其中有一个元素表示为 void (*func)(); 我知道 void 指针通常用于函数指针,但我似乎无法定义该函数。我不断收到取消引用指向不完整类型的指针。我用谷歌搜索了一下但没有结
我正在尝试使用 Coldfusion 9 从 ning 网络获取凭证,所以首先这是测试 api 的 curl 语法: curl -k https://external.ningapis.com/xn/
这个问题已经有答案了: Does C have references? (2 个回答) 已关闭 4 年前。 我正在学习 C 语言引用,这是我的代码: #include int main(void)
我是一名优秀的程序员,十分优秀!