[PATCH] cpukit/score: Avoid overflow in multiplication

Kinsey Moore kinsey.moore at oarcorp.com
Tue Jan 16 20:02:29 UTC 2024


The two operands are 16 bit and the result is being saved into a
larger type. Reduce the possibility of an overflow during multiplication
by using the larger type as an operand.
---
 cpukit/score/src/objectextendinformation.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c
index 414766f219..f9c51c3bec 100644
--- a/cpukit/score/src/objectextendinformation.c
+++ b/cpukit/score/src/objectextendinformation.c
@@ -115,7 +115,8 @@ Objects_Maximum _Objects_Extend_information(
    * Allocate the name table, and the objects and if it fails either return or
    * generate a fatal error depending on auto-extending being active.
    */
-  object_block_size = extend_count * information->object_size;
+  object_block_size = extend_count;
+  object_block_size *= information->object_size;
   new_object_block = _Workspace_Allocate( object_block_size );
   if ( new_object_block == NULL ) {
     return 0;
-- 
2.39.2



More information about the devel mailing list