CurlFile::CReadState::HeaderCallback: internally use std::string instead of char*
authorKarlson2k <k2k@narod.ru>
Tue, 13 Aug 2013 22:16:19 +0000 (02:16 +0400)
committerKarlson2k <k2k@narod.ru>
Sun, 27 Oct 2013 00:27:56 +0000 (04:27 +0400)
xbmc/filesystem/CurlFile.cpp

index 05b6d0c..426ad70 100644 (file)
@@ -147,24 +147,19 @@ size_t CCurlFile::CReadState::HeaderCallback(void *ptr, size_t size, size_t nmem
     m_headerdone = false;
   }
 
+  std::string inString;
   // libcurl doc says that this info is not always \0 terminated
-  char* strData = (char*)ptr;
-  int iSize = size * nmemb;
-
-  if (strData[iSize] != 0)
-  {
-    strData = (char*)malloc(iSize + 1);
-    strncpy(strData, (char*)ptr, iSize);
-    strData[iSize] = 0;
-  }
-  else strData = strdup((char*)ptr);
+  const char* strBuf = (const char*)ptr;
+  const size_t iSize = size * nmemb;
+  if (strBuf[iSize - 1] == 0)
+    inString.assign(strBuf, iSize - 1); // skip last char if it's zero
+  else
+    inString.append(strBuf, iSize);
 
-  if(strcmp(strData, "\r\n") == 0)
+  if(inString == "\r\n")
     m_headerdone = true;
 
-  m_httpheader.Parse(strData);
-
-  free(strData);
+  m_httpheader.Parse(inString);
 
   return iSize;
 }