diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/lscript/lscript_byteconvert.h | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to '')
-rw-r--r-- | linden/indra/lscript/lscript_byteconvert.h | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/linden/indra/lscript/lscript_byteconvert.h b/linden/indra/lscript/lscript_byteconvert.h index a9b0094..e17f3fc 100644 --- a/linden/indra/lscript/lscript_byteconvert.h +++ b/linden/indra/lscript/lscript_byteconvert.h | |||
@@ -166,8 +166,15 @@ inline void bytestream_int2float(U8 *stream, S32 &offset) | |||
166 | inline bool bytestream2char(char *buffer, const U8 *stream, S32 &offset, S32 buffsize) | 166 | inline bool bytestream2char(char *buffer, const U8 *stream, S32 &offset, S32 buffsize) |
167 | { | 167 | { |
168 | S32 source_len = strlen( (const char *)stream+offset ); | 168 | S32 source_len = strlen( (const char *)stream+offset ); |
169 | strncpy( buffer, (const char *)stream+offset, buffsize-1 ); | 169 | S32 copy_len = buffsize - 1; |
170 | buffer[buffsize-1] = 0; | 170 | if( copy_len > source_len ) |
171 | { | ||
172 | copy_len = source_len; | ||
173 | } | ||
174 | |||
175 | // strncpy without \0 padding overhead | ||
176 | memcpy( buffer, stream+offset, copy_len ); | ||
177 | buffer[copy_len] = 0; | ||
171 | 178 | ||
172 | offset += source_len + 1; // advance past source string, include terminating '\0' | 179 | offset += source_len + 1; // advance past source string, include terminating '\0' |
173 | 180 | ||
@@ -1073,28 +1080,20 @@ inline void safe_instruction_float2bytestream(U8 *stream, S32 &offset, F32 value | |||
1073 | 1080 | ||
1074 | inline void safe_instruction_bytestream2char(char *buffer, U8 *stream, S32 &offset, S32 buffsize) | 1081 | inline void safe_instruction_bytestream2char(char *buffer, U8 *stream, S32 &offset, S32 buffsize) |
1075 | { | 1082 | { |
1076 | bool safe; | 1083 | // This varies from the old method. Previously, we would copy up until we got an error, |
1077 | while ( (safe = safe_instruction_check_address(stream, offset, 1)) | 1084 | // then halt the script via safe_isntruction_check_address. Now we don't bother |
1078 | && buffsize-- | 1085 | // copying a thing if there's an error. |
1079 | &&(*buffer++ = *(stream + offset++))) | ||
1080 | ; | ||
1081 | 1086 | ||
1082 | // Return if it ended in a null (success) or if script error handling is taking over | 1087 | if( safe_instruction_check_address(stream, offset, strlen( (const char *)stream + offset ) + 1 ) ) |
1083 | if( !safe || (0 == *(buffer-1)) ) | ||
1084 | { | 1088 | { |
1085 | return; // Yep. Success. | 1089 | // Takes the same parms as this function. Won't overread, per above check. |
1090 | bytestream2char( buffer, stream, offset, buffsize ); | ||
1091 | } | ||
1092 | else | ||
1093 | { | ||
1094 | // Truncate - no point in copying | ||
1095 | *buffer = 0; | ||
1086 | } | 1096 | } |
1087 | |||
1088 | // Defensive mode. We copied at least one char and ran out of space before | ||
1089 | // null termination. Add the terminator... | ||
1090 | *(buffer-1) = 0; | ||
1091 | |||
1092 | // ...and advance offset past the end of the data as if we copied the rest. If we | ||
1093 | // violate the safety check, script error handling will protect us. No need to | ||
1094 | // keep advancing. | ||
1095 | while( safe_instruction_check_address(stream, offset, 1) | ||
1096 | && *( stream + offset++ ) ) | ||
1097 | ; | ||
1098 | } | 1097 | } |
1099 | 1098 | ||
1100 | inline void safe_instruction_bytestream_count_char(U8 *stream, S32 &offset) | 1099 | inline void safe_instruction_bytestream_count_char(U8 *stream, S32 &offset) |