It's possible that the "rq_anon" pointer is either pointing to an invalid 
memory location, OR the string pointed to by rq_anon is not null-terminated

Randy

-----Original Message-----
From: ns-users-boun...@isi.edu [mailto:ns-users-boun...@isi.edu] On Behalf Of 
Reza Karimi
Sent: Sunday, June 08, 2014 1:27 PM
To: ns-users@ISI.EDU
Subject: [ns] Problem with const char*


Hi



Please take a look at the following code:

---------------------------------------

const char *x="Reza";

if (strcmp(rq->rq_anon,x) == 0)

{

  //Do something

}

--------------------------------------

"rq" is a pointer to the header of RREQ packet and "rq_anon" is a pointer to 
const data. This is a part of my routing protocol. Making is OK. The problem is 
that when I run my Tcl program related to this routing protocol, segmentation 
falut occurs. But when I changed this code to:

---------------------------------------

if (rq->rq_anon == "Reza")

{

  //Do something

}

--------------------------------------

it works! with one warning that is expected. So what is the problem? Is it a 
bug in NS?



______________________________________________________

Reza Karimi, M.Sc.

Faculty of Electrical and Computer Engineering (ECE)

K.N.Toosi University of Technology

Tehran, IRAN.




P PLEASE CONSIDER OUR ENVIRONMENT BEFORE PRINTING THIS EMAIL.

This e-mail (including any attachments) is confidential and may be legally 
privileged. If you are not an intended recipient or an authorized 
representative of an intended recipient, you are prohibited from using, copying 
or distributing the information in this e-mail or its attachments. If you have 
received this e-mail in error, please notify the sender immediately by return 
e-mail and delete all copies of this message and any attachments. Thank you.

Reply via email to