TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Jasen Betts
from: Neil Heller
date: 2004-05-14 12:38:00
subject: Basic C syntax

NH> In the function msg_receive, fd is a socket connected to a
NH> remote  Internet client. 

NH> What is wrong with msg_receive? Suggest a fix.

JB> are you #including io.h ( for read())

NH>    #define MAXVALS 65536
NH>    typedef struct _msg_t {
NH>      unsigned int num;
NH>      unsigned int values[MAXVALS];
NH>    } msg_t;

JB> how wide is your size_t  (16 bit compilers won't like that but they
JB> should complain...)

IIRC the application was for a 16-bit embedded system.  I remember 
something about 16-bit systems have a real limit vis array access of 
65520 bytes.  This would be 131,072 bytes.  Is that what you were 
meaning?


NH>    int msg_receive(int fd, msg_t *m)
NH>    {
NH>      size_t sz = sizeof(unsigned int);
NH>      assert(m);
NH>      if( read(fd, (void *)&m->num, sz) < sz)

JB> what byte-order are you (and the sender) using

Why cast the number as a pointer to void?

Considering that read is unbuffered, would the last statement of 
msg_received overrun any 16-bit buffer?

þ CMPQwk 1.42 999

--- Maximus/2 3.01
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
SEEN-BY: 633/267 270
@PATH: 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.