Board index » cppbuilder » Hello everyone!

Hello everyone!


2004-02-19 09:42:04 AM
cppbuilder20
I have a very strange problem. My application contains a few auto-created
forms and a few available, created by me. At the beginning of the program I
parse text from the text file, put it into the class "document", and each
object of class "document" I insert into the STL queue<document>. After
inserting few objects (queue<document>::push(const document&)) an access
violation in GetMem.inc occurs.
This is the implementation of class document:
class document{
char title[500];
char URL[70];
char contents[500];
};
Each instance of document I'm filling by simple strcpy(instance.title,
_title), strcpy(instance.URL, _URL), etc... I'm sure, that source's strings
aren't longer, than destination sizes...
waht to do?
 
 

Re:Hello everyone!

Wojciech Bobiatyński wrote:
Quote
I have a very strange problem. My application contains a few auto-created
forms and a few available, created by me. At the beginning of the program I
parse text from the text file, put it into the class "document", and each
object of class "document" I insert into the STL queue<document>. After
inserting few objects (queue<document>::push(const document&)) an access
violation in GetMem.inc occurs.

This is the implementation of class document:
class document{
char title[500];
char URL[70];
char contents[500];
};

Each instance of document I'm filling by simple strcpy(instance.title,
_title), strcpy(instance.URL, _URL), etc... I'm sure, that source's strings
aren't longer, than destination sizes...
waht to do?
Are you sure there is a 0 at the end of your source strings ?
 

Re:Hello everyone!

"Wojciech Bobiatyński" < XXXX@XXXXX.COM >wrote:
Quote
I have a very strange problem. My application contains a few auto-created
forms and a few available, created by me. At the beginning of the program
I
parse text from the text file, put it into the class "document", and each
object of class "document" I insert into the STL queue<document>. After
inserting few objects (queue<document>::push(const document&)) an access
violation in GetMem.inc occurs.

This is the implementation of class document:
class document{
char title[500];
char URL[70];
char contents[500];
};
Besides what Obones says (you should check it with assertions), why not use
std::string?
--
Daniel
 

{smallsort}

Re:Hello everyone!

Quote
After inserting few objects (queue<document>::push(const document&))
an access violation in GetMem.inc occurs.
What does the AV say? The AV will list the address of the instruction
that caused the error. Put a breakpoint on that address using the CPU
view and rerun the app. When the breakpoint is hit, look at the callstack.
Quote
class document{
char title[500];
char URL[70];
char contents[500];
};
Seems like a fairly useless class to me. All the data is private.
Quote
Each instance of document I'm filling by simple strcpy(instance.title,
_title), strcpy(instance.URL, _URL), etc... I'm sure, that source's strings
aren't longer, than destination sizes...
Even so, you should consider using strncpy instead. Also, are you
initializing the strings? Why not use std::string instead?
h^2
 

Re:Hello everyone!

Thank you all very much. It was- like OBones said- I was copying to char
title[500] pom.Substring(1,500), which was very silly idea and now I'm
realised that very clearly. Above that I allocated tab=
(class*)calloc(licz_test,sizeof(class)); in entirely another module, where
licz_test wasn't initialized (even more stupidly than previous). So-
evevrything seems to be clear now. I'm finishing my project- if I have more
question I lay on your help!
regards
Wojtek
Uzytkownik "Harold Howe [TeamB]" < XXXX@XXXXX.COM >napisal w wiadomosci
Quote
>After inserting few objects (queue<document>::push(const document&))
>an access violation in GetMem.inc occurs.

What does the AV say? The AV will list the address of the instruction
that caused the error. Put a breakpoint on that address using the CPU
view and rerun the app. When the breakpoint is hit, look at the callstack.


>class document{
>char title[500];
>char URL[70];
>char contents[500];
>};

Seems like a fairly useless class to me. All the data is private.

>Each instance of document I'm filling by simple strcpy(instance.title,
>_title), strcpy(instance.URL, _URL), etc... I'm sure, that source's
strings
>aren't longer, than destination sizes...

Even so, you should consider using strncpy instead. Also, are you
initializing the strings? Why not use std::string instead?

h^2