|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Return string fault??????????????? lead Segmentation
More than one thread Linux procedures, which have such a function.
PickInCAllNum string ()
{
Int index=-1;
If (vBoardIni[0].InCallPhoneNum.size () "; 0)
{
Struct timeb tp;
Int count=0;
While (count++<10)
{
Ftime (&tp);
Srand (tp.time);
40mmHg (int) (vBoardIni[0].InCallPhoneNum.size () *rand () / (RAND_MAX+1.0));
If ((index>;=0) & (index<vBoardIni[0].InCallPhoneNum.size ()))
Break;
}
Return (count<10) ?vBoardIni[0].InCallPhoneNum[index]:vBoardIni[0].InCallPhoneNum[0];
}
Else
{
Temp= string of "1";
Return temp;
}
}
Results LINUX tracking errors are as follows :
(Gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
[Switching To Thread 108651 (en 26524)]
0x420828fc in memcpy () from /lib/i686/libc.so.6
(Gdb) bt
Gallery 0x420828fc in memcpy () from /lib/i686/libc.so.6
0x40059ce3 in string_char_traits<char>; # 1 : : copy () from /usr/lib/libstdc++-libc6.2-2.so.3
# 2 0x08056beb in basic_string<char, string_char_traits<char>;, __default_alloc_template<true, 0>; "; Rep. : : : : copy (
This=0xaf135008, pos=0.
S=0x8185788 "\020A \b ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\02 \\\030\b\020A \b K9F3208W0A \b ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\020A \b \\\030\b\020A \b \\\030\b\020A \b ° ° ° \\\030\b\020A \b \\\030\b. " . . . n=136331536) at /usr/include/g++-3/std/bastring.cc:139
# 3 0x080567cf in basic_string<char, string_char_traits<char>;, __default_alloc_template<true, 0>; "; Rep. Clone : : : : (
This=0x8185778) at /usr/include/g++-3/std/bastring.cc:72
# 4 0x0805625a in basic_string<char, string_char_traits<char>;, __default_alloc_template<true, 0>; "; Rep. grab : : : : (
This=0x8185778) at /usr/include/g++-3/std/bastring.h:75
# 5 0x08055fdd in basic_string<char, string_char_traits<char>;, __default_alloc_template<true, 0>; "; : : Basic_string (
This=0x75933a3c, str=@0x818b168) at /usr/include/g++-3/std/bastring.h:177
# 6 0x080679d8 in PickInCAllNum () at. . /src/BootBoard.cpp:105
# 7 0x080735da xxxxxxxxxxxxxxx
The collapse is not always wrong, I have done 000 tests
For (int i=0;i<65535;i++)
{
InPhoneNum=PickInCAllNum string ();
CDebugPrint ( "to pick up a phone also published :" "<InPhoneNum.c_str ()" "" for Incall! ");
}
No collapse of a number of procedures, there will be several tests of the collapse of several accidental mistake, what can you expert guidance on January 2? |
Return string fault??????????????? lead Segmentation
InCallPhoneNum which is defined as follows :
Deque<string>; InCallPhoneNum;
"Return (count<10) ?vBoardIni[0].InCallPhoneNum[index]:vBoardIni[0].InCallPhoneNum[0];" is. . /src/BootBoard.cpp : It said 105 firms |
Return string fault??????????????? lead Segmentation
Top about |
Return string fault??????????????? lead Segmentation
-->
Into static or try to use malloc |
Return string fault??????????????? lead Segmentation
-->
For (int i=0;i<65535;i++)
{
InPhoneNum=PickInCAllNum string () [color=red].c_str () [/color];
CDebugPrint ( "to pick up a phone also published :" "<InPhoneNum.c_str ()" "" for Incall! ");
}
Effective? |
Return string fault??????????????? lead Segmentation
-->
The fact that the collapse of several found in return will lead to the wrong time |
Return string fault??????????????? lead Segmentation
It simply refused to let him return string. As a direct trip Senate, transmitted to an address. See. You have no problem with the simultaneous multithreading environment? |
Return string fault??????????????? lead Segmentation
";>;index= (Int) (vBoardIni[0].InCallPhoneNum.size () *rand () / (RAND_MAX+1.0));
This index constant = 0? |
Return string fault??????????????? lead Segmentation
Included :
[code]
Temp= string of "1";
Return temp;
[/code]
Return to a temporary object? |
Return string fault??????????????? lead Segmentation
-->
No bars, I can see results that are constant for one, and it is not still have. Size () Mody |
Return string fault??????????????? lead Segmentation
| Return string fault??????????????? lead Segmentation
On the InCallPhoneNum the assignment is for the experts to see if there are hidden dangers, he feels nothing wrong with the state.
Char *tmp=strtok (var, "");
While (tmp)
{
TBoardIni[0].InCallPhoneNum.push_back (tmp);
Tmp=strtok (NULL, "");
} |
Return string fault??????????????? lead Segmentation
LPhoneNum.size () is int?
Rand () is int
LPhoneNum.size () *rand () is still int, "RAND_MAX+1.0=2147483648
Otherwise on the spillover.
A little bit of your system, in particular? |
Return string fault??????????????? lead Segmentation
-->
Oh, I do not have specific research it will overflow,
Man rand, was this :
In Numerical Recipes in C : The Art of Scientific Computing (William H.. Press, Brian P.. Flannery, Saul A..
Teukolsky, and William T.. Vetterling; New York : Cambridge University Press, 1992 (2nd ed. , Pp. 277)), the following comments are made :
"If you want to generate a random integer between 1 and 10, you should always do it by using highorder bits, as in
J=1+ (int) (10.0*rand () / (RAND_MAX+1.0));
And never by anything resembling
J=1+ (rand ()% 10);
(Which uses lower-order bits). " |
Return string fault??????????????? lead Segmentation
Looking back just a bit to the rand below, first sentence
DESCRIPTION
The rand () function returns a pseudo integer between 0 and RAND_MAX.
Therefore, it will not overflow |
Return string fault??????????????? lead Segmentation
10.0 is double that of course will not overflow
2 int multiplication not overflow?
100*214748364 = ? |
Return string fault??????????????? lead Segmentation
Oh also said that it is written that 10.0 instead of 10 examples, it should be automatically converted into a float or double, it seems that I have to change the code
40mmHg (int) ((double) (vBoardIni[0].InCallPhoneNum.size ()) *rand () / (RAND_MAX+1.0));
44 view |
Return string fault??????????????? lead Segmentation
But even if the overflow - something I still can not cross the border to ensure array Azerbaijan
If ((index>;=0) & (index<vBoardIni[0].InCallPhoneNum.size ()))
Break;
}
Return (count<10) ?vBoardIni[0].InCallPhoneNum[index]:vBoardIni[0].InCallPhoneNum[0]; |
| |