Click here to Skip to main content
15,850,917 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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 ;

0./lib/ [2bb42730]
1./lib/ [2b9dee58]
2./lib/ [2b9df42c]
3./lib/ [2bb39b40]
5./lib/ (*)())
7./lib/ [2ba8a4bc]
8./lib/ new(unsigned int)
9./lib/ int, unsigned int, std::allocator<char> const&)
10./lib/<char> const&, unsigned int)
11./lib/ const&)

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 ;
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;
            xmlParamType = eParamNull;
    void event2()
        case ItemSurname:
             itemSurname = tempValue;
        case ItemFirstname:
             itemFirstname = tempValue;
        case ItemOffice:
             itemOffice = tempValue;
        case ItemMobile:
             itemMobile = tempValue;
        case ItemPrivate:
             itemPrivate = tempValue;
        case ItemEmail:
             itemEmail = tempValue;
        case ItemCompany:
             itemCompany = tempValue;
        case ItemAddress:
             itemAddress = tempValue;
        case UniqueId:
             uniqueId = tempValue;

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

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 ..

Updated 15-Jul-14 5:40am
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:
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
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
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 ?
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