[dia] [scan-build] Argument with 'nonnull' attribute passed null



commit af345911f6fa415ffaf2fb0f0c9b00c3719277fb
Author: Hans Breuer <hans breuer org>
Date:   Sun Sep 27 14:35:44 2009 +0200

    [scan-build] Argument with 'nonnull' attribute passed null
    
    Ensure to never strncpy to NULL and not shrink the temporary storage.
    The NULL case might not happen in the wild, but
    http://clang-analyzer.llvm.org/ suggests to change.

 objects/UML/class.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/objects/UML/class.c b/objects/UML/class.c
index f28d623..3cc384b 100644
--- a/objects/UML/class.c
+++ b/objects/UML/class.c
@@ -1018,11 +1018,13 @@ umlclass_draw_operationbox(UMLClass *umlclass, DiaRenderer *renderer, Element *e
             if (part_opstr_len < part_opstr_need) {
               part_opstr_len = part_opstr_need;
               part_opstr = g_realloc (part_opstr, part_opstr_need);
+            } else {
+              /* ensure to never strncpy to NULL amd not shrink */
+              part_opstr = g_realloc (part_opstr, MAX(part_opstr_need, part_opstr_len));
             }
             strncpy( part_opstr, opstr, wrap_pos);
             memset( part_opstr+wrap_pos, '\0', 1);
-          }
-          else   {
+          } else   {
             part_opstr_need = ident + wrap_pos - last_wrap_pos + 1;
             if (part_opstr_len < part_opstr_need) {
               part_opstr_len = part_opstr_need;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]