Skip to content

minor bugs in vli_add and vli_sub #3

Description

@mikeryan

This patch addresses some corner cases in vli_add and vli_sub. I have not tested it for correctness.

From ba453211161ed86b945ad7df44160959ee40a28f Mon Sep 17 00:00:00 2001
From: Ildar Muslukhov <ildar@redacted>
Date: Sat, 12 Apr 2014 11:37:23 -0700
Subject: [PATCH] Fixed a bug in the vli_add/vli_sub functions (handleding of a
 corner case, when p_right[i] == 0xff)

---
 ecc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ecc.c b/ecc.c
index bc2ee39..00976f2 100644
--- a/ecc.c
+++ b/ecc.c
@@ -220,7 +220,7 @@ static uint8_t vli_add(uint8_t *p_result, uint8_t *p_left, uint8_t *p_right)
         uint8_t l_sum = p_left[i] + p_right[i] + l_carry;
         if(l_sum != p_left[i])
         {
-            l_carry = (l_sum < p_left[i]);
+            l_carry = (l_sum < p_left[i]) | ((l_sum == p_left[i]) && (l_carry));
         }
         p_result[i] = l_sum;
     }
@@ -237,7 +237,7 @@ static uint8_t vli_sub(uint8_t *p_result, uint8_t *p_left, uint8_t *p_right)
         uint8_t l_diff = p_left[i] - p_right[i] - l_borrow;
         if(l_diff != p_left[i])
         {
-            l_borrow = (l_diff > p_left[i]);
+            l_borrow = (l_diff > p_left[i]) | ((l_diff == p_left[i]) && (l_borrow));
         }
         p_result[i] = l_diff;
     }
-- 
1.8.5.2 (Apple Git-48)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions