aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/lscript/lscript_byteconvert.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/lscript/lscript_byteconvert.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/lscript/lscript_byteconvert.h37
1 files changed, 31 insertions, 6 deletions
diff --git a/linden/indra/lscript/lscript_byteconvert.h b/linden/indra/lscript/lscript_byteconvert.h
index 42f71e8..a9b0094 100644
--- a/linden/indra/lscript/lscript_byteconvert.h
+++ b/linden/indra/lscript/lscript_byteconvert.h
@@ -162,13 +162,19 @@ inline void bytestream_int2float(U8 *stream, S32 &offset)
162 float2bytestream(stream, offset, fpvalue); 162 float2bytestream(stream, offset, fpvalue);
163} 163}
164 164
165inline void bytestream2char(char *buffer, const U8 *stream, S32 &offset) 165// Returns true on success, return false and clip copy on buffer overflow
166inline bool bytestream2char(char *buffer, const U8 *stream, S32 &offset, S32 buffsize)
166{ 167{
167 while ((*buffer++ = *(stream + offset++))) 168 S32 source_len = strlen( (const char *)stream+offset );
168 ; 169 strncpy( buffer, (const char *)stream+offset, buffsize-1 );
170 buffer[buffsize-1] = 0;
171
172 offset += source_len + 1; // advance past source string, include terminating '\0'
173
174 return source_len < buffsize;
169} 175}
170 176
171inline void char2bytestream(U8 *stream, S32 &offset, char *buffer) 177inline void char2bytestream(U8 *stream, S32 &offset, const char *buffer)
172{ 178{
173 while ((*(stream + offset++) = *buffer++)) 179 while ((*(stream + offset++) = *buffer++))
174 ; 180 ;
@@ -1065,11 +1071,30 @@ inline void safe_instruction_float2bytestream(U8 *stream, S32 &offset, F32 value
1065 } 1071 }
1066} 1072}
1067 1073
1068inline void safe_instruction_bytestream2char(char *buffer, U8 *stream, S32 &offset) 1074inline void safe_instruction_bytestream2char(char *buffer, U8 *stream, S32 &offset, S32 buffsize)
1069{ 1075{
1070 while ( (safe_instruction_check_address(stream, offset, 1)) 1076 bool safe;
1077 while ( (safe = safe_instruction_check_address(stream, offset, 1))
1078 && buffsize--
1071 &&(*buffer++ = *(stream + offset++))) 1079 &&(*buffer++ = *(stream + offset++)))
1072 ; 1080 ;
1081
1082 // Return if it ended in a null (success) or if script error handling is taking over
1083 if( !safe || (0 == *(buffer-1)) )
1084 {
1085 return; // Yep. Success.
1086 }
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 ;
1073} 1098}
1074 1099
1075inline void safe_instruction_bytestream_count_char(U8 *stream, S32 &offset) 1100inline void safe_instruction_bytestream_count_char(U8 *stream, S32 &offset)