Changeset 16384 in vbox
- Timestamp:
- Jan 29, 2009 6:16:07 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
include/VBox/com/string.h (modified) (2 diffs)
-
src/VBox/Main/glue/string.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r16369 r16384 126 126 127 127 /** 128 * Allocates memory for a string capable to store \a aSize - 1 characters 129 * plus the terminating zero character. If \a aSize is zero, or if a130 * memory allocation error occurs, this object will become null.128 * Allocates memory for a string capable to store \a aSize - 1 characters; 129 * in other words, aSize includes the terminating zero character. If \a aSize 130 * is zero, or if a memory allocation error occurs, this object will become null. 131 131 */ 132 132 Bstr &alloc (size_t aSize) … … 389 389 390 390 /** 391 * Allocates memory for a string capable to store \a aSize - 1 characters392 * plus the terminating zero character. If \a aSize is zero, or if a393 * memory allocation error occurs, this object will become null.391 * Allocates memory for a string capable to store \a aSize - 1 bytes (not characters!); 392 * in other words, aSize includes the terminating zero character. If \a aSize 393 * is zero, or if a memory allocation error occurs, this object will become null. 394 394 */ 395 395 Utf8Str &alloc (size_t aSize) -
trunk/src/VBox/Main/glue/string.cpp
r16378 r16384 68 68 return ret; // return empty string on bad encoding 69 69 70 size_t len = psz - pFirst; 71 #if 1 72 char *psz = (char*)RTMemAlloc(len + 1); 73 memcpy(psz, pFirst, len); 74 psz[len] = '\0'; 75 ret = psz; 76 RTMemFree(psz); 77 #else /* A proposal that saves a memcpy and alloc/free: */ 78 ret.alloc(len + 1); 79 memcpy(ret.str, pFirst, len); 80 ret.str[len] = '\0'; 81 #endif 70 size_t cbCopy = psz - pFirst; 71 ret.alloc(cbCopy + 1); 72 memcpy(ret.str, pFirst, cbCopy); 73 ret.str[cbCopy] = '\0'; 82 74 } 83 75 }
Note:
See TracChangeset
for help on using the changeset viewer.

