[balsa/wip/gtk4: 152/351] print-object-text: Assign PhraseRegion explicitly



commit 8801684e4af8cb42f4173885b73f423ebae7e6ec
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Feb 7 19:14:34 2018 -0500

    print-object-text: Assign PhraseRegion explicitly
    
    The scan-build tool doesn't recognize g_memdup() as initializing the
    newly allocated memory. Allocating it and then explicitly initializing
    it by assignment is accepted, and probably generates about the same
    code.

 src/balsa-print-object-text.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/src/balsa-print-object-text.c b/src/balsa-print-object-text.c
index 298a459..033e5c1 100644
--- a/src/balsa-print-object-text.c
+++ b/src/balsa-print-object-text.c
@@ -917,17 +917,18 @@ collect_attrs(GList * all_attr, guint offset, guint len)
             && region->start_index <= offset + len)
            || (region->end_index >= offset
                && region->end_index <= offset + len)) {
+            /* scan-build does not see this as initializing this_reg:
            PhraseRegion *this_reg =
                g_memdup(region, sizeof(PhraseRegion));
+             */
+            PhraseRegion *this_reg;
+
+            this_reg = g_new(PhraseRegion, 1);
+            *this_reg = *region;
+
+            this_reg->start_index = MAX(0,   this_reg->start_index - offset);
+            this_reg->end_index   = MIN(len, this_reg->end_index   - offset);
 
-           if (this_reg->start_index < offset)
-               this_reg->start_index = 0;
-           else
-               this_reg->start_index -= offset;
-           if (this_reg->end_index > offset + len)
-               this_reg->end_index = len;
-           else
-               this_reg->end_index -= offset;
            attr = g_list_prepend(attr, this_reg);
        }
        all_attr = all_attr->next;


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