|
Hello;
I want to want to write queue library on ANSI C. But i'm getting Damage: after normal block #42 at 0x00341000 error when executed free(ptr_queue[0]) statement. The statement frees first m_queue mallocation when i use free(ptr_queue[0]) statement?. Am i right? If not, why?
Code at below;
struct queue {
int id;
char* buffer_area;
};
int i = 0;
struct queue *m_queue;
struct queue *ptr_queue[100];
m_queue = (struct queue*)malloc(sizeof(m_queue));
m_queue->id = 1;
m_queue->buffer_area = "job-1";
ptr_queue[i] = m_queue;
i++;
m_queue = (struct queue*)malloc(sizeof(m_queue));
m_queue->id = 2;
m_queue->buffer_area = "job-2";
ptr_queue[i] = m_queue;
i++;
free(ptr_queue[0]);
ptr_queue[0] = NULL;
Thank you...
|
|
|
|
|
You are correct, but that isn't the problem.
The problem is that you are trashing memory after the allocated data. If you look at your example source, you will see you are allocating sizeof (m_queue) bytes. This is in error since the sizeof (m_queue) is just the size of a pointer, not the actual structure. Either change it to sizeof (*m_queue) or sizeof (struct queue).
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Yes. You are right. I can't believe myself!!! I'm stupid!!!
Thank you...
|
|
|
|
|
hello all
i am facing some problem when dealing with registry in HKLM(Local Machine).
it's working fine in case for debug execute, where as when i try to run same snippet in release it's not able to read.
it works fine if we just put
char Buff[xx];
wsprintf(Buff,"%s",data from regkae value);
looking for early comments
Anshuman
anshuman
|
|
|
|
|
It sounds like you are overrunning a buffer on the stack. You can always enable debug information in your release build and debug it. Of course, the optimizations will make things a little strange, but it might help.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
crazy Yaar.
check Query for registry. by jon d. 27 june
Anshu
|
|
|
|
|
I have a dialog box that I pop up as a progress indicator. There are two program modes, manual and automatic. In the manual mode, the user clicks ok when the progress is complete, which closes the progress dialog window. In automatic, when the progress is done, I need it to automatically close the dialog. The problem is, if I call DestroyWindow, without the user having clicked somewhere, I get a "User breakpoint called from [address]". Anybody had this problem before...seems kind of weird.
- John
|
|
|
|
|
Use EndDialog() function.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
To programatically close the dialog, fake an OK (or Cancel) button-click by doing:
PostMessage (WM_COMMAND, IDOK);
Post Message (WM_COMMAND, IDCANCEL);
This should cause your dialog to close as if the user clicked OK.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I have a CListCtrl with scrolling, but I was under the impression that the horizontal scrolling would only show up when needed.
However, in my case the scroll shows up everytime, even when the text is quite small.
Am i doing something particularly wrong? And what forces the horizontal scroll to show up anyways?
|
|
|
|
|
See the properies of that resource, you have the hScollBar propierty enable. In this case always you will see the Hrozontal Scrollbar visible, when the text is small it will be disabled, but when the text is large, it will be enable.
I hope to help you.
Carlos Antollini.
Is friday at night in Argentina I need =>
|
|
|
|
|
And what forces the horizontal scroll to show up anyways?
You didn't say which mode your list is in. If it's report view, then the horizontal scrollbar appears when the sum of all column widths is larger than the width of the control.
--Mike--
http://home.inreach.com/mdunn/
Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese?
Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say?
|
|
|
|
|
Hi everyone! Im having a little problem with this code.
I have B1 and B2 class offpring of some B class and an A class that have linked lists to B1 and B2 references to the objects it "owns".
class B {};
class B1 : public B {};
class B2 : public B {};
typedef struct B1node
{ B1 *B1obj;
B1node *next; } B1node;
typedef struct B2node
{ B2 *B2obj;
B2node *next; } B2node;
class A {
B1node *list1;
B2node *list2;
A &operator=(A& parent) {
B1node *p=parent.list1;
B2node *q=parent.list2;
B1 *obj1;
B2 *obj2;
// we are just creating new B1,B2 objects for the new
// A object and addin them to A
while(p) {
obj1=new(B1);
add_b1(*obj1);
p=p->next;
};
while(q) {
obj2=new(B2);
add_b2(*obj2);
q=q->next;
};
};
void add_b1(B1& obj1) {
B1node *p=new(B1node);
p->B1obj=&obj1;
p->next=list1; // HERE IT'S THE BUGGY SH*T !
list1=p;
};
void add_b2(B2& obj2) {
B2node *q=new(B2node);
q->B2obj=&obj2;
q->next=list2;
list2=q;
};
};
When i call the add methods regularly from main() it does just fine, but when they are called from the =OP they give some "General Protection Fault" at runtime just like they were some misused pointer. The fact is im startin to believe this could be some freaky pointer bug in MSVC++ 6.0, althought i do know that most probably its my fault.
I havent yet downloaded any SPx so i wonder if it could be a bug or its something im doing wrong (do you see some obvious flaw?)
The error jumps out (on add_b1()) when trying to assign list1 as the next node of p! that's pretty unusual!
ANY help or suggestion would be hugely apreciated
my mood stages through this issue:
then then then then
THX!
________________________________________________
Those that have really found the meaning, dont find it meaningful
|
|
|
|
|
What is the value of p?
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
P and q are just references to the lists that are defined
locally on the method
________________________________________________
Those that have really found the meaning, dont find it meaningful
|
|
|
|
|
No, I mean when the program crashes, what is the value of p? That value can usually tell you a LOT about what the program is doing wrong.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Ok, i know what might be the problem
until now i hadnt said something because i didnt know it was important, but know i figured its the root of the problem.. but since i think the problem has to be reformulated, please forgive me and consider this thread closed, im posting a new thread in a moment...
________________________________________________
Those that have really found the meaning, dont find it meaningful
|
|
|
|
|
Not an answer to your direct question, but an alternative would be to use the std::list container from the STL. You can simplify this code greatly by using STL containers, and if you can live with the cost of object copying, then reworking the lists as lists of 'b1' and 'b2' objects instead of pointers will enable you to eliminate virtually all of this code.
|
|
|
|
|
I have three columns. Each column has alot of text. The user can move the divider, but is there away of letting the user horizontally scroll an individual column without moving the divider?
Please, please any response anyone can give me will be greatly appreciated.
Sincerely,
DanYELL (an overworked graduate student)
|
|
|
|
|
The standard list control can't do that. You might want to look into a grid control (such as Chris Maunder's, right here at this site) so you can resize the rows and show more text.
--Mike--
http://home.inreach.com/mdunn/
Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese?
Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say?
|
|
|
|
|
You might try enabling the tooltip control by item/subitem so that when you hover your mouse in a item/subitem the tooltip would popup and show you the rest of the text. I'm also assuming you're in report mode. BTW - dundas has published a good tooltip control somewhere on this website that has many neat features.
|
|
|
|
|
I add a class from dll to my mfc single document (without doc view support) project in CMainFrame::OnCreate function i create my activex control wich is wrapped by the class i added ussing it's create function, then i use it's SetWindowPos function to change it's size in CMainFrame::OnSize function, it's working perfect but when i minimize the main window and then i restore it back, the ActiveX control crashes, saying "Devision by zero".
What is the problem ???
|
|
|
|
|
Hi,
I am using gethostbyname(strHost) method.
and in the LPHOSTENT structure, i am getting two IPs in the
h_addr_list[0] = 192.0.2.172 //My local machine IP assigned by Domain.
h_addr_list[1] = 202.23.24.220 //IP address assigned by Internet Service
//Provider when I dial an internet connection.
Now the same function returns values of same type on a different machine but woth reverse sequence.
Can anybody tell me the way I can check which IP is assigned by ISP and which is my local IP.
Thanks in advance..
Iftikhar Ahmad Dar
|
|
|
|
|
Lee Hamel has posted a nice library to CodeGuru which does exactly what you want. Click here to get it.
Regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Just check which ip address that's not a private one.
Private ip addresses are in those ranges:
10.0.0.0. - 10.255.255.255.255
192.168.0.0 - 192.168.255.255
172.16.0.0 - 172.31.255.255
If an ip address is in any of those ranges, it's not routable on the internet, and therefore not assigned by an ISP...
h_addr_list[0] = 192.0.2.172 //My local machine IP assigned by Domain.
It's a bad idea to use public ip addresses on a LAN...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|