Ticket #3693: mc-3693-syntax.c-Cleanup-unsafe-loop-optimizations-compiler-.patch

File mc-3693-syntax.c-Cleanup-unsafe-loop-optimizations-compiler-.patch, 1.5 KB (added by and, 7 years ago)
  • src/editor/syntax.c

    From e6146633d6fe5866a78a9469dae51cd7565224e3 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Tue, 6 Dec 2016 10:33:40 +0000
    Subject: [PATCH] (syntax.c) Cleanup unsafe-loop-optimizations compiler warning
    
    Found by GCC 6.2.0.
    
    syntax.c: In function 'edit_get_rule':
    syntax.c:572:9: error: cannot optimize possibly infinite loops [-Werror=unsafe-loop-optimizations]
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/editor/syntax.c | 8 ++++----
     1 file changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/src/editor/syntax.c b/src/editor/syntax.c
    index 20130d6..056060a 100644
    a b edit_get_rule (WEdit * edit, off_t byte_index) 
    569569 
    570570    if (byte_index > edit->last_get_rule) 
    571571    { 
    572         for (i = edit->last_get_rule + 1; i <= byte_index; i++) 
     572        for (i = edit->last_get_rule; i < byte_index; i++) 
    573573        { 
    574574            off_t d = SYNTAX_MARKER_DENSITY; 
    575575 
    576             apply_rules_going_right (edit, i); 
     576            apply_rules_going_right (edit, i + 1); 
    577577 
    578578            if (edit->syntax_marker != NULL) 
    579579                d += ((syntax_marker_t *) edit->syntax_marker->data)->offset; 
    580580 
    581             if (i > d) 
     581            if (i + 1 > d) 
    582582            { 
    583583                syntax_marker_t *s; 
    584584 
    585585                s = g_new (syntax_marker_t, 1); 
    586                 s->offset = i; 
     586                s->offset = i + 1; 
    587587                s->rule = edit->rule; 
    588588                edit->syntax_marker = g_slist_prepend (edit->syntax_marker, s); 
    589589            }