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

New Message on cochindotnet

-----------------------------------------------------------
From: J.K.
Message 5 in Discussion


Hi,



The  buf[bytesRead] = '\0';  will overrun the
buffer when bytesread == length.



I believe buf = new char[length];  should be buf
= new char[length+1];  





Have a nice day,



Jayakrishnan K

[ MVP - Visual C++ ]







At 04:53 AM 7/18/03 -0700, you wrote:

New Message on
cochindotnet




reading stdin C++ (pipe)




Reply
  Reply to Sender   Recommend Message 4 in Discussion 
From: mail2dolly 




Hi,




I am now using ReadFile in a loop to read stdin, It works fine for small amounts of 
data but when the data piped is large, it crashes saying "The Process tried to write 
to a nonexistent pipe" ( For Eg dir /s|prog.exe on the C drive at cmd)




Any idea how I can get past this? 
Ignorant question : Can I use anonymous pipe concept here to read in from the pipe. Or 
that is used only with user created pipes?




I am doing something like this :




if(GetFileType(h) == FILE_TYPE_PIPE)
{
while(1)
{
buf = new char[length];
bResult = ReadFile(h, buf, length, &bytesRead, NULL);




buf[bytesRead] = '\0';
if(bResult bytesRead == 0 )break; //EOF
buf = 0;
bytesRead = 0;
}
}




ReadFile throws an error sometimes, and sometimes it works fine. I think I am missing 
something here, if somebody has any idea, please mail back.




Thanks and Regards,
Dolly




View other groups in this category. 




Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes 




To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings. 




Need help? If you've forgotten your password, please go to Passport Member Services. 
For other questions or feedback, go to our Contact Us page. 




If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list. 
Remove my e-mail address from cochindotnet. 


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

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/cochindotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to