You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by frano <fm...@us.ibm.com> on 2009/01/14 22:42:59 UTC

Problem using binToText for Long data

I have the following code: 

struct unit_struct {
    unsigend char *version[LEN];  
    ULONG board_id; 
    unsigned char *unit[LEN];
};


const unsigned long ud_brd_id = units_data->board_id; 
XMLCh brd_id[100]; 
XMLSize_t maxchars = sizeof(units_data->board_id); 
const unsigned int rad = 10; 
try {
    XMLString::binToText(ud_brd_id, brd_id, maxchars, rad); 
} catch (const XMLException& exc) {
    cout << " Got exception \n";
    char *exc_msg = XMLString::transcode(exc.getMessage()); 
    cout << "Exception msg is " << exc_msg << "\n";
}


When the code is executed I get a segmentation fault on the
XMLString::binToText call......  

Any ideas of what I am doing wrong ? 

Fran 
-- 
View this message in context: http://www.nabble.com/Problem-using-binToText-for-Long-data-tp21465842p21465842.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Problem using binToText for Long data

Posted by David Bertoni <db...@apache.org>.
frano wrote:
> I have the following code: 
> 
> struct unit_struct {
>     unsigend char *version[LEN];  
>     ULONG board_id; 
>     unsigned char *unit[LEN];
> };
This is a very strange struct given how you're calling binToText().  Is 
version really an array of _pointers_ to unsigned chars? Did you mean 
"unsigned char version[LEN}" instead, which is an array of unsigned 
chars of length "LEN"?

Please show more code, especially the code that populates the "version" 
and "unit" fields.

Dave

Re: Problem using binToText for Long data

Posted by Lucian Cosoi <lu...@gmail.com>.
2009/1/15 frano wrote

>
> I have tried using maxchar values of up to 100 and  I still get a
> segmentation fault......
>
> If it's any help here is what the data (the board_id) is:
>
> As viewed in a file in Hex:   0100F120
> As displayed on the screen after being read from the file:  552665089 (this
> is the result of doing a cout of the data)....
>
> Fran
>

Did you call XMLPlatformUtils::Initialize() before this code and not call a
matching XMLPlatformUtils::Terminate?

Is "binToText" the only function causing a segmentation fault? (i.e. can you
call at the same point in the code another Xerces function without
problems?)

If yes, perhaps you could show us the exact code you are working with - I
don't see the memory allocation for the "units_data" structure and I am
fairly sure there is no "unsigend char" type...

Re: Problem using binToText for Long data

Posted by frano <fm...@us.ibm.com>.
I have tried using maxchar values of up to 100 and  I still get a
segmentation fault......  

If it's any help here is what the data (the board_id) is: 

As viewed in a file in Hex:   0100F120
As displayed on the screen after being read from the file:  552665089 (this
is the result of doing a cout of the data)....

Fran


Lucian Cosoi wrote:
> 
> 2009/1/14 frano wrote:
> 
>>
>> I have the following code:
>>
>> struct unit_struct {
>>    unsigend char *version[LEN];
>>    ULONG board_id;
>>    unsigned char *unit[LEN];
>> };
>>
>>
>> const unsigned long ud_brd_id = units_data->board_id;
>> XMLCh brd_id[100];
>> XMLSize_t maxchars = sizeof(units_data->board_id);
>> const unsigned int rad = 10;
>> try {
>>    XMLString::binToText(ud_brd_id, brd_id, maxchars, rad);
>> } catch (const XMLException& exc) {
>>    cout << " Got exception \n";
>>    char *exc_msg = XMLString::transcode(exc.getMessage());
>>    cout << "Exception msg is " << exc_msg << "\n";
>> }
>>
>>
>> When the code is executed I get a segmentation fault on the
>> XMLString::binToText call......
>>
>> Any ideas of what I am doing wrong ?
>>
>> Fran
>>
> 
> You specify to the "binToText" function that the maximum number of
> characters the resulting string should be represented on is sizeof(ULONG)
> -
> which I assume is 4 or whatever number of bytes your system represents
> unsigned long on.
> 
> I guess the number stored in "board_id" is represented on more digits than
> that, and it doesn't fit.
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-using-binToText-for-Long-data-tp21465842p21477049.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Problem using binToText for Long data

Posted by Lucian Cosoi <lu...@gmail.com>.
2009/1/14 frano wrote:

>
> I have the following code:
>
> struct unit_struct {
>    unsigend char *version[LEN];
>    ULONG board_id;
>    unsigned char *unit[LEN];
> };
>
>
> const unsigned long ud_brd_id = units_data->board_id;
> XMLCh brd_id[100];
> XMLSize_t maxchars = sizeof(units_data->board_id);
> const unsigned int rad = 10;
> try {
>    XMLString::binToText(ud_brd_id, brd_id, maxchars, rad);
> } catch (const XMLException& exc) {
>    cout << " Got exception \n";
>    char *exc_msg = XMLString::transcode(exc.getMessage());
>    cout << "Exception msg is " << exc_msg << "\n";
> }
>
>
> When the code is executed I get a segmentation fault on the
> XMLString::binToText call......
>
> Any ideas of what I am doing wrong ?
>
> Fran
>

You specify to the "binToText" function that the maximum number of
characters the resulting string should be represented on is sizeof(ULONG) -
which I assume is 4 or whatever number of bytes your system represents
unsigned long on.

I guess the number stored in "board_id" is represented on more digits than
that, and it doesn't fit.