Thanks for the replies everyone. I am about to start up on this code again, but first -
I use valgrind, but it doesn't crash with valgrind...it just exits normally. According to Valgrind there is nothing that I can really do about it. I do get some messages at the start though saying -
Code:
==5275== Thread 3:
==5275== Conditional jump or move depends on uninitialised value(s)
==5275== at 0x40250BB: strlen (mc_replace_strmem.c:282)
==5275== by 0x805F438: udpserver::communicate() (char_traits.h:263)
==5275== by 0x805B6F3: ServerControl::udp_comm_thread(void*) (servercontrol.cpp:196)
==5275== by 0x403E954: start_thread (pthread_create.c:300)
==5275== by 0x447BE7D: clone (clone.S:130)
==5275== Uninitialised value was created by a stack allocation
==5275== at 0x805F406: udpserver::communicate() (udpserver.cpp:141)
==5275==
==5275== Syscall param socketcall.recvfrom(fromlen_in) points to uninitialised byte(s)
==5275== at 0x4046428: recvfrom (socket.S:100)
==5275== by 0x805B6F3: ServerControl::udp_comm_thread(void*) (servercontrol.cpp:196)
==5275== by 0x403E954: start_thread (pthread_create.c:300)
==5275== by 0x447BE7D: clone (clone.S:130)
==5275== Address 0x59d634c is on thread 3's stack
==5275== Uninitialised value was created by a stack allocation
==5275== at 0x805F406: udpserver::communicate() (udpserver.cpp:141)
==5275==
==5275== Syscall param socketcall.recvfrom(fromlen_out) points to uninitialised byte(s)
==5275== at 0x4046428: recvfrom (socket.S:100)
==5275== by 0x805B6F3: ServerControl::udp_comm_thread(void*) (servercontrol.cpp:196)
==5275== by 0x403E954: start_thread (pthread_create.c:300)
==5275== by 0x447BE7D: clone (clone.S:130)
==5275== Address 0x59d634c is on thread 3's stack
==5275== Uninitialised value was created by a stack allocation
==5275== at 0x805F406: udpserver::communicate() (udpserver.cpp:141)
The weird part is that servercontrol.cpp:196 is just calling a function (myUDP->communicate()). And udpserver.cpp:141 is just the start of that function. I would say there aren't any problems in there, but apparently I missed something. The function is small, its just -
Code:
void udpserver::communicate() { //line 141
struct sockaddr_storage their_addr;
socklen_t their_addr_size;
socklen_t addr_len;
int num_read;
char in[255];
while(!done) {
num_read = recvfrom(fd, in, 255 , 0, (struct sockaddr *)&their_addr, &addr_len);
if (num_read < 0 ) {}
else {
//cutoff index
int term = 10;
while(isdigit(in[term]) || in[term] == '-')
term++;
in[term] = '\0';
//std::cout<<"\nRead: "<<in;
//check which client
if(in[2] == '1')
get_message(in, 1);
else
get_message(in, 2);
//wait and clear in
usleep(5000);
memset(&in, 0, term);
} //end else
} //end while
close(fd);
} //END COMMUNICATE
If you see anything that stands out can you tell me?