c*****t 发帖数: 1879 | 1 【 以下文字转载自 Database 讨论区 】
发信人: coconut (向唐僧大师学习中), 信区: Database
标 题: Mysterious PgSQL 8.3 crash
发信站: BBS 未名空间站 (Fri Feb 8 12:32:47 2008), 站内
写 stored procedure 的时候,发现 sprintf, elog, ereport 等统统
会造成 crash 。可是 8.2.6 底下好好的。比如
strcpy (buffer, "test"); 执行没问题,但是
sprintf (buffer, "%s", "test"); 就 crash。
例如:
CREATE FUNCTION TCDB.t_create_table(cstring) RETURNS void
AS '/projects/workspace/tcdb/src/server/libmy_utils.dll', 't_create_table'
LANGUAGE C STRICT;
Datum t_create_table (PG_FUNCTION_ARGS)
{
|
T*******i 发帖数: 4992 | 2 0xc0000005是啥?查了么?
【在 c*****t 的大作中提到】 : 【 以下文字转载自 Database 讨论区 】 : 发信人: coconut (向唐僧大师学习中), 信区: Database : 标 题: Mysterious PgSQL 8.3 crash : 发信站: BBS 未名空间站 (Fri Feb 8 12:32:47 2008), 站内 : 写 stored procedure 的时候,发现 sprintf, elog, ereport 等统统 : 会造成 crash 。可是 8.2.6 底下好好的。比如 : strcpy (buffer, "test"); 执行没问题,但是 : sprintf (buffer, "%s", "test"); 就 crash。 : 例如: : CREATE FUNCTION TCDB.t_create_table(cstring) RETURNS void
|
c*****t 发帖数: 1879 | 3 C0000005 STATUS_ACCESS_VIOLATION The instruction at 0x%08lx
referenced memory at 0x%08lx. The memory could not be %s.
【在 T*******i 的大作中提到】 : 0xc0000005是啥?查了么?
|
T*******i 发帖数: 4992 | 4 it looks like a memory leak. hehe
【在 c*****t 的大作中提到】 : C0000005 STATUS_ACCESS_VIOLATION The instruction at 0x%08lx : referenced memory at 0x%08lx. The memory could not be %s.
|
X****r 发帖数: 3557 | 5 你试过用小一点的buffer吗?比如16而不是8192。万一是新版本的PqSQL把栈限制得更
小了?
【在 c*****t 的大作中提到】 : C0000005 STATUS_ACCESS_VIOLATION The instruction at 0x%08lx : referenced memory at 0x%08lx. The memory could not be %s.
|
c*****t 发帖数: 1879 | 6 试了 200,也不行。不是 stack 的问题。这个问题类似
char* foo = "abc";
foo[0] = 'd';
因为 official windows binary 是用 vc++ compiled,而我的 dll 是用
MinGW 编的,以为是这问题。但是我尝试用 MinGW 编译了 PgSQL 8.3 以
后也是同样的问题。
sigh,8.3 里刚好有我急切需要的 composite type array 支持,但是这
个问题让俺止步。俺这个程序在 8.2.6 上执行好好的,但是 8.2.6 没
composite type array 支持我下面要加的东西就没法写 :(
【在 X****r 的大作中提到】 : 你试过用小一点的buffer吗?比如16而不是8192。万一是新版本的PqSQL把栈限制得更 : 小了?
|
X****r 发帖数: 3557 | 7 如果是这样的话把字符串常量都放到可以修改的地方试试?比如
char format[] = "%s"; // or use static if needed
char text[] = "test";
sprintf(buffer, format, text);
【在 c*****t 的大作中提到】 : 试了 200,也不行。不是 stack 的问题。这个问题类似 : char* foo = "abc"; : foo[0] = 'd'; : 因为 official windows binary 是用 vc++ compiled,而我的 dll 是用 : MinGW 编的,以为是这问题。但是我尝试用 MinGW 编译了 PgSQL 8.3 以 : 后也是同样的问题。 : sigh,8.3 里刚好有我急切需要的 composite type array 支持,但是这 : 个问题让俺止步。俺这个程序在 8.2.6 上执行好好的,但是 8.2.6 没 : composite type array 支持我下面要加的东西就没法写 :(
|
c*****t 发帖数: 1879 | 8 试过了。照样 crash 。所以我才奇怪。
【在 X****r 的大作中提到】 : 如果是这样的话把字符串常量都放到可以修改的地方试试?比如 : char format[] = "%s"; // or use static if needed : char text[] = "test"; : sprintf(buffer, format, text);
|
c*****t 发帖数: 1879 | 9 Finally got it fixed. The new postgresql pre-compiled binary was
created using VC8 instead of MinGW which was used in previous versions,
so are the library files it bundles with it. I was using MinGW and
there are some incompatibilities between these two (particulary for
the vararg I guess). That's why some stuff works fine and some aren't.
Also, postgres re-defines sprintf etc to use its own routine, that's
why I was looking at the wrong place. |