Changeset 60145 in vbox for trunk/src/VBox/Main
- Timestamp:
- Mar 23, 2016 8:51:33 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r59117 r60145 139 139 140 140 return VINF_SUCCESS; 141 } 142 143 144 /** 145 * Purge string of non-UTF-8 encodings and control characters. 146 * 147 * @returns String length (excluding terminator). 148 * @param psz The string to purge. 149 */ 150 static size_t usbPurgeEncoding(char *psz) 151 { 152 /* Beat it into valid UTF-8 encoding. */ 153 RTStrPurgeEncoding(psz); 154 155 /* Look for control characters. */ 156 size_t offSrc; 157 for (offSrc = 0; ; offSrc++) 158 { 159 char ch = psz[offSrc]; 160 if (RT_UNLIKELY(RT_C_IS_CNTRL(ch))) 161 { 162 /* Found a control character! Replace tab by space and remove all others. */ 163 size_t offDst = offSrc; 164 for (;; offSrc++) 165 { 166 ch = psz[offSrc]; 167 if (RT_C_IS_CNTRL(ch)) 168 { 169 if (ch == '\t') 170 ch = ' '; 171 else 172 continue; 173 } 174 psz[offDst++] = ch; 175 if (ch == '\0') 176 break; 177 } 178 return offDst - 1; 179 } 180 if (ch == '\0') 181 break; 182 } 183 return offSrc - 1; 141 184 } 142 185 … … 328 371 if (psz) 329 372 { 330 RTStrPurgeEncoding(psz);373 usbPurgeEncoding(psz); 331 374 *ppsz = psz; 332 375 return VINF_SUCCESS; … … 1305 1348 if (cchRead > 0 && (size_t) cchRead < sizeof(szBuf)) 1306 1349 { 1307 RTStrPurgeEncoding(szBuf);1350 usbPurgeEncoding(szBuf); 1308 1351 Dev->pszProduct = RTStrDup(szBuf); 1309 1352 } … … 1313 1356 if (cchRead > 0 && (size_t) cchRead < sizeof(szBuf)) 1314 1357 { 1315 RTStrPurgeEncoding(szBuf);1358 usbPurgeEncoding(szBuf); 1316 1359 Dev->pszSerialNumber = RTStrDup(szBuf); 1317 1360 Dev->u64SerialHash = USBLibHashSerial(szBuf); … … 1322 1365 if (cchRead > 0 && (size_t) cchRead < sizeof(szBuf)) 1323 1366 { 1324 RTStrPurgeEncoding(szBuf);1367 usbPurgeEncoding(szBuf); 1325 1368 Dev->pszManufacturer = RTStrDup(szBuf); 1326 1369 }
Note:
See TracChangeset
for help on using the changeset viewer.