Skip to content

Commit 7f564a4

Browse files
committed
x
1 parent 99a8a5e commit 7f564a4

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

cores/arduino/zephyr/api/String.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bool arduino_string_replace_bytes(
192192
unsigned int find_len,
193193
const char *replace,
194194
unsigned int replace_len);
195-
void arduino_string_remove(char *buffer, unsigned int *len, unsigned int index, unsigned int count);
195+
unsigned int arduino_string_remove(char *buffer, unsigned int len, unsigned int index, unsigned int count);
196196
void arduino_string_reverse(char *buffer, unsigned int len);
197197
void arduino_string_get_bytes(
198198
const char *buffer,

cores/arduino/zephyr/api/String.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,11 @@ inline void String::replace(const String &find, const String &replace) {
400400
}
401401

402402
inline void String::remove(unsigned int index) {
403-
arduino_string_remove(buffer, &len, index, static_cast<unsigned int>(-1));
403+
len = arduino_string_remove(buffer, len, index, static_cast<unsigned int>(-1));
404404
}
405405

406406
inline void String::remove(unsigned int index, unsigned int count) {
407-
arduino_string_remove(buffer, &len, index, count);
407+
len = arduino_string_remove(buffer, len, index, count);
408408
}
409409

410410
inline void String::toLowerCase(void) {

rust/src/string.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,18 +1203,17 @@ pub extern "C" fn arduino_string_replace_bytes(
12031203
#[unsafe(no_mangle)]
12041204
pub extern "C" fn arduino_string_remove(
12051205
buffer: *mut c_char,
1206-
len: *mut c_uint,
1206+
len: c_uint,
12071207
index: c_uint,
12081208
count: c_uint,
1209-
) {
1210-
if buffer.is_null() || len.is_null() || count == 0 {
1211-
return;
1209+
) -> c_uint {
1210+
if buffer.is_null() || count == 0 {
1211+
return len;
12121212
}
12131213

1214-
// SAFETY: len is non-null and writable.
1215-
let current_len = unsafe { *len };
1214+
let current_len = len;
12161215
if index >= current_len {
1217-
return;
1216+
return current_len;
12181217
}
12191218

12201219
let remaining = current_len - index;
@@ -1225,13 +1224,14 @@ pub extern "C" fn arduino_string_remove(
12251224
let tail = (current_len - index - remove_count) as usize;
12261225
let new_len = current_len - remove_count;
12271226

1228-
// SAFETY: `buffer`/`len` are non-null. Copy ranges are within the same allocation and may
1229-
// overlap. Writing the terminating NUL at `new_len` is within bounds.
1227+
// SAFETY: `buffer` is non-null. Copy ranges are within the same allocation and may overlap.
1228+
// Writing the terminating NUL at `new_len` is within bounds.
12301229
unsafe {
12311230
ptr::copy(buffer.add(src), buffer.add(dst), tail);
1232-
*len = new_len;
12331231
*buffer.add(new_len as usize) = 0;
12341232
}
1233+
1234+
new_len
12351235
}
12361236

12371237
#[unsafe(no_mangle)]

0 commit comments

Comments
 (0)