ACE 的 BUG ? ACE_Process_Options:setenv,该怎么解决
ACE 的 BUG ? ACE_Process_Options::setenv
C++NPv1 8.3 的例子程序,会 Memory Fault.
#109 0x2838a53e in vsnprintf () from /lib/libc.so.7
#110 0x281aa607 in ACE_Process_Options::setenv (this=0xbfbfe094, variable_name=0x8048fad "PROGRAM=%s",
format=0xbfbfed16 "factorial") at OS_NS_stdio.inl:1044
#111 0x08048b99 in main (argc=1, argv=0xbfbfeba4) at factorial.cpp:25
发现希望调用的函数是
int ACE_Process_Options::setenv (const ACE_TCHAR *format, ...),
结果调用的却是
int ACE_Process_Options::setenv (const ACE_TCHAR *variable_name,
const ACE_TCHAR *format, ...)
这样设计函数有问题啊,
options.setenv ("PROGRAM=%s", ACE::basename (argv[0]));
可以两个都可以调用啊。
8.3 The ACE_Process_Options Class
C++NPv1 8.3 的例子程序,会 Memory Fault.
#109 0x2838a53e in vsnprintf () from /lib/libc.so.7
#110 0x281aa607 in ACE_Process_Options::setenv (this=0xbfbfe094, variable_name=0x8048fad "PROGRAM=%s",
format=0xbfbfed16 "factorial") at OS_NS_stdio.inl:1044
#111 0x08048b99 in main (argc=1, argv=0xbfbfeba4) at factorial.cpp:25
发现希望调用的函数是
int ACE_Process_Options::setenv (const ACE_TCHAR *format, ...),
结果调用的却是
int ACE_Process_Options::setenv (const ACE_TCHAR *variable_name,
const ACE_TCHAR *format, ...)
这样设计函数有问题啊,
options.setenv ("PROGRAM=%s", ACE::basename (argv[0]));
可以两个都可以调用啊。
8.3 The ACE_Process_Options Class
/**
* @file factorial.cpp
* @brief
*/
#include "ace/OS.h"
#include "ace/ACE.h"
#include "ace/Process.h"
int main(int argc, char *argv[])
{
ACE_Process_Options options;
FILE *fp = NULL;
char *n_env = NULL;
int n;
if (argc == 1) {
// Top-level process.
n_env = ACE_OS::getenv ("FACTORIAL");
n = n_env == 0 ? 0 : atoi (n_env);
options.command_line ("%s %d", argv[0], n == 0 ? 10 : n);
const char *working_dir = ACE_OS::getenv ("WORKING_DIR");
if (working_dir) options.working_directory (working_dir);
fp = fopen ("factorial.log", "a");
options.setenv ("PROGRAM=%s", ACE::basename (argv[0]));
} else {
fp = fopen ("factorial.log", "a");
if (atoi (argv[1]) == 1) {
// Base case
fprintf (fp, "[%s|%d]: base case\n",
ACE_OS::getenv ("PROGRAM"), ACE_OS::getpid ());
fclose (fp);
return 1;
} else {
n = atoi (argv[1]);
options.command_line ("%s %d", argv[0], n - 1);