DemesneGH commented on code in PR #253:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2509321635


##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> 
Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| 
{
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, Cannot copy all bytes");
+                return Err(ErrorKind::BadParameters.into());
+            }
+
+            // Copy the serialized JSON string into the buffer.
+            let len = bytes.len();

Review Comment:
   move this line to line68 so that the line70 can use this variable `len`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to