Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,
It is difficult to write the whole code block, because it is too long. I just want to say that it crashes in string assignment part. There is an enum, and I assign the string value to enum variables.

The backtrace is as follows ;


VB
# BACKTRACE:
0./lib/libc.so.0(kill+0x24) [2bb42730]
1./lib/libpthread.so.0(pthread_kill+0xa8) [2b9dee58]
2./lib/libpthread.so.0(raise+0x34) [2b9df42c]
3./lib/libc.so.0(abort+0xac) [2bb39b40]
4./lib/libstdc++.so.6(__gnu_cxx::__verbose_terminate_handler()++.so.6
5./lib/libstdc++.so.6(__cxxabiv1::__terminate(void (*)())++.so.6
6./lib/libstdc++.so.6(std::terminate()++.so.6
7./lib/libstdc++.so.6(__cxa_throw+0xb8) [2ba8a4bc]
8./lib/libstdc++.so.6(operator new(unsigned int)++.so.6
9./lib/libstdc++.so.6(std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&)++.so.6
10./lib/libstdc++.so.6(std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned int)++.so.6
11./lib/libstdc++.so.6(std::string::assign(std::string const&)++.so.6


Could you please help about the cause of crash ? What can be the cause ??
Thanks in advance,

[EDIT - OP code from comment]
Here is the code block. It always crashes in these two events ;
C++
void event1(){
     {
        tempValue = "";
        if(pName == ReasonTag)
            xmlParamType = ReasonForRequest;
        else if(pName == FailureMsgTag)
            xmlParamType = FailureMessage;
        else if(pName == SchemaTag)
        {
            if(pDataAtts[0] == SchemaNameTag)
                schemaName = pDataAtts[1];
        }
        else if(pName == SurnameTag)
            xmlParamType = ItemSurname;
        else if(pName == FirstnameTag)
            xmlParamType = ItemFirstname;
        else if(pName == OfficeTag)
            xmlParamType = ItemOffice;
        else if(pName == MobileTag)
            xmlParamType = ItemMobile;
        else if(pName == EmailTag)
            xmlParamType = ItemEmail;
        else if(pName == CompanyTag)
            xmlParamType = ItemCompany;
        else if(pName == AddressTag)
            xmlParamType = ItemAddress;
        else if(pName == UniqueIdTag)
            xmlParamType = UniqueId;
        else
            xmlParamType = eParamNull;
 
    }
}
 
    void event2()
    {
        switch(xmlParamType)
    {
        case ItemSurname:
             itemSurname = tempValue;
        break;
 
        case ItemFirstname:
             itemFirstname = tempValue;
        break;
 
        case ItemOffice:
             itemOffice = tempValue;
        break;
 
        case ItemMobile:
             itemMobile = tempValue;
        break;
 
        case ItemPrivate:
             itemPrivate = tempValue;
        break;
 
        case ItemEmail:
             itemEmail = tempValue;
        break;
 
        case ItemCompany:
             itemCompany = tempValue;
        break;
 
        case ItemAddress:
             itemAddress = tempValue;
        break;
 
        case UniqueId:
             uniqueId = tempValue;
        default:
            break;
    }
}



[EDIT oryginal_content = "comment"]
Here is the definitions of variables ;

C++
enum xmlParamType{ ParamNull, ReasonForRequest, SchemaName, ItemSurname, ItemFirstname, ItemOffice, ItemMobile, ItemEmail, ItemCompany, ItemAddress, ItemJobFunction, UniqueId };
OString tempValue;

And the other variables are all OString type variables, like itemSurname, itemFirstName ..

[/EDIT]
Posted
Updated 15-Jul-14 4:40am
v3
Comments
CPallini 15-Jul-14 8:02am    
The cause is your code. The specific offending part I cannot locate, without seeing it.
WuRunZhe 15-Jul-14 8:05am    
Well, without your code, anyone can find out the reason. Pls, rewrite your question with your main problem code part.
no_-_namee 15-Jul-14 8:17am    
--- this comment is now the part of question ---
Maciej Los
WuRunZhe 15-Jul-14 8:20am    
Could explain more clearly about each variable's type?
no_-_namee 15-Jul-14 8:29am    
--- this comment is now the part of question ---
Maciej Los

The assignment of a value to a variable of type std::string can only crash if the value passed is disguised as a type that it isn't and contains value that doesn't fit the expectation tied to that type.

In this case, you are passing variables of type OString directly, implying that the type OString has an implicit conversion operator to a type that can be assigned to a std::string variable. Most likely this type is const char*. Check the implementation of the following operator:
C++
OString::operator const char*() const

The actual function may be missing a const or two, but it must exist, or the assignment wouldn't even compile! In the implementation code, check what is returned.

There are at least two things that can go wrong in this code:
1. Returning an incorrect value, possibly by type-casting something to const char*
2. Returning a pointer that wasn't correctly initialized or assigned; this may also be due to an error in the code for the assignment operator.

If these hints don't help you identify the bug, show us the code of the relevant OString operators (assignment and conversion operators, mostly).
 
Share this answer
 
Comments
Maciej Los 17-Jul-14 9:24am    
BIG 5!
no_-_namee 17-Jul-14 9:31am    
Hi Stefan,
You are right . There is a code line which includes type casting between OString and const char** as follows ;

name (OString) = data[1] (const char**);

This code is written a long time ago. And I should fix this crash. How can I resolve it ?

Thanks in advance,
debug the code and you will find out that assign a string to an enum is a real bad idea.

Enums are typed int.
 
Share this answer
 
Comments
Richard MacCutchan 16-Jul-14 11:28am    
He doesn't; see the comments above.
KarstenK 16-Jul-14 14:30pm    
A "tuff guy" but if doesnt work the way is proofed to be wrong :-O
Richard MacCutchan 16-Jul-14 14:49pm    
Since we still have no idea "what" doesn't work, it is all pure speculation. :(
no_-_namee 17-Jul-14 7:27am    
I get a detailed message with GDB. It is as follows ;

#0 0x2b8b0410 in std::string::assign (this=0x7e3ff798, __s=0x2c080124 <Address 0x2c080124 out of bounds>, __n=0)
at /opt/ifx/Sources/inca/v2.5.0/toolchain/uclibc_toolchain_src/buildroot/toolchain_build_mips_nofpu/gcc-3.4.4-final/mips-linux-uclibc/libstdc++-v3/include/bits/basic_string.h:194
#1 0x2c0693f4 in ?? ()

Do you have any new idea about the cause of crash ?
Thanks,
KarstenK 17-Jul-14 7:47am    
yes or maybe - if i could look on your code in which it happend.

My tip is some type mismatch: assigning a string value to a enum or vice versa.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900