File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed
Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ char *strcpy(char *restrict dst, const char *restrict src)
9898 dst [i ] = src [i ];
9999 i ++ ;
100100 }
101+ dst [i ] = '\0' ;
101102
102103 return dst ;
103104}
Original file line number Diff line number Diff line change @@ -208,13 +208,14 @@ pub fn monitor_serialise_names(
208208 let name_bytes = name. as_bytes ( ) ;
209209 let start = ( i + 1 ) * max_name_len;
210210 // Here instead of giving an error we simply take the minimum of the name
211- // and how large of a name we can encode
212- let name_length = std:: cmp:: min ( name_bytes. len ( ) , max_name_len) ;
211+ // and how large of a name we can encode. The name length is one less than
212+ // the maximum since we still have to add the null terminator.
213+ let name_length = std:: cmp:: min ( name_bytes. len ( ) , max_name_len - 1 ) ;
213214 let end = start + name_length;
214215 names_bytes[ start..end] . copy_from_slice ( & name_bytes[ ..name_length] ) ;
215216 // These bytes will be interpreted as a C string, so we must include
216217 // a null-terminator.
217- names_bytes[ start + max_name_len - 1 ] = 0 ;
218+ names_bytes[ end ] = 0 ;
218219 }
219220
220221 names_bytes
You can’t perform that action at this time.
0 commit comments