Dear Sir:
I am sorry to trouble you, but this is important for me, and I need you
help, thank you very much.
The problem is the following cod:
#include <stdio.h>
#include <ctype.h>
#include<stdlib.h>
#include <stdarg.h>
#include <string.h>
void msg(const char* type, ...)
{
va_list ap;
char* buf;
va_start(ap,type);
while(1) {
char* arg = va_arg(ap, char*);
if (arg == NULL || strcmp(arg, "") == 0) {
printf("break...\n");
break;
}
printf("----------%s------------\n",arg);
//len += strnlen(arg, 200)+1;
}
va_end(ap);
}
void main(void)
{
msg("char","a","b","c","d");
}
when it is run in Red hat, the result is :
begin........
----------a------------
----------b------------
----------c------------
----------d------------
break...
but in solaris:
----------a------------
----------b------------
----------c------------
----------d------------
----------� ا���|------------
----------��
�ZYX��]���------------
----------Z�2------------
----------����------------
----------[�â------------
----------P
�������_��1��n~------------
----------n
�|�|� ا���|------------
----------�|------------
----------[��------------
----------�z------------
break...
That means if the program is run in solaris, some problems will occur
like 'core dumped".I don't know how to resolve this problem. Of course
we can add a parameter of the count of parameters and do something in a
for iterator, but there are many place to modify, so can you give me
some suggestions to resolve this problems in solaris environment? thank
you very much. I am looking forward to you reply.
The same problem is also occured in lib/mgmt/mgmt_common_lib.c
char*
mgmt_new_msg(const char* type, ...)
{
va_list ap;
int len;
char* buf;
/* count the total len of fields */
len = strnlen(type, MAX_STRLEN)+1;
va_start(ap,type);
while(1) {
char* arg = va_arg(ap, char*);
if (arg == NULL) {
break;
}
len += strnlen(arg, MAX_STRLEN)+1;
}
va_end(ap);
/* alloc memory */
buf = (char*)mgmt_malloc(len+1);
if (buf == NULL) {
return NULL;
}
/* assign the first field */
snprintf(buf,len,"%s", type);
/* then the others */
va_start(ap, type);
while(1) {
char* arg = va_arg(ap, char*);
if (arg == NULL) {
break;
}
strncat(buf, "\n", len);
strncat(buf, arg, len);
}
va_end(ap);
return buf;
}
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/