Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#47 singed value should be used for variable currLen

open
nobody
None
5
2011-12-06
2011-12-06
Greg Hongge Ren
No

The variable currLen of Client::RunTCP() and Client::Run() should be decalred as singed long, rather than the unsigned long. It is used as return value of system call - write(). The occasional error returned is interpreted as a huge writes length and cause hovoc.

Error was observed on our internal development platform, but the nature of this error can occur in any system. Here is a fix for a simple fix. It is used ot illustrate the problem, and may not be the clean fix (in a git diff format):

diff --git a/src/Client.cpp b/src/Client.cpp
index 71a5b5c..1d5d4c5 100755
--- a/src/Client.cpp
+++ b/src/Client.cpp
@@ -116,7 +116,7 @@ const double kSecs_to_usecs = 1e6;
const int kBytes_to_Bits = 8;

void Client::RunTCP( void ) {
- unsigned long currLen = 0;
+ long currLen = 0;
struct itimerval it;
max_size_t totLen = 0;

@@ -203,7 +203,7 @@ void Client::RunTCP( void ) {

void Client::Run( void ) {
struct UDP_datagram* mBuf_UDP = (struct UDP_datagram*) mBuf;
- unsigned long currLen = 0;
+ long currLen = 0;

int delay_target = 0;
int delay = 0;

Discussion