Date: Friday, December 16, 2005 @ 21:27:26
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: JavaSocket.cpp (1.21 -> 1.22)

zero-ing only the last byte in the receive buffer of readUTF().
Commented bugs and arcane techniques in readUTF() and writeUTF().


----------------+
 JavaSocket.cpp |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)


Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.21 carob/src/JavaSocket.cpp:1.22
--- carob/src/JavaSocket.cpp:1.21       Wed Dec 14 17:47:52 2005
+++ carob/src/JavaSocket.cpp    Fri Dec 16 21:27:26 2005
@@ -188,13 +188,13 @@
     throw (SocketIOException, UnexpectedException)
 {
   wstring fctName(L"JavaSocket::writeJavaUTF");
-  // Convert size to net format
+  // Size of the wide string in bytes, including the wide terminating null
   uint16_t strlenPlusOne = (str.length()+1)*sizeof(wchar_t);
   
   // FIXME: we don't support inline zeros. We should get rid of c_str
   const wchar_t* oriStr = str.c_str();
+ // guessing the max converted size like this is hopelessly wrong. By chance 
it's usually enough.
   uint8_t* utfStr = new uint8_t[strlenPlusOne];
-  
   size_t countConverted;
   mbstate_t mbstate = {0};
 
@@ -220,7 +220,7 @@
     {
       if (isVerboseEnabled())
         logVerbose(fctName, L"Ok. Sending string");
-      //Then send the string itself
+      // Send the encoded string (wcsrtombs() does not count the terminating 
zero)
       sendToSocket(fctName, L"UTF string", utfStr, countConverted, 
MSG_NOSIGNAL);
     }
   }
@@ -241,10 +241,10 @@
   //First get size
   if (receiveFromSocket(fctName, L"UTF string size", &lenRecNet, 
sizeof(lenRecNet), 0))
   {
-    lenRec = ntohs(lenRecNet);
+    lenRec = ntohs(lenRecNet); // number of bytes to come
   
-    uint8_t* utfStr = new uint8_t[lenRec+1];
-    memset(utfStr, 0, lenRec+1);
+    uint8_t* utfStr = new uint8_t[lenRec+1]; // add a zero to C-terminate it
+    utfStr[lenRec] = 0;
     if (receiveFromSocket(fctName, L"UTF string", utfStr, lenRec, 0))
     {
       // FIXME: we don't support inline zeros. We should get rid of c_str

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to