Skip to content
  • Philip Withnall's avatar
    gunidecomp: Fix a false positive from the static analyser · 05158475
    Philip Withnall authored
    
    
    scan-build was complaining that the `wc_buffer[old_n_wc]` in `cc =
    COMBINING_CLASS (wc_buffer[old_n_wc])` could dereference memory off the
    end of the initialised `wc_buffer` array. It came to this conclusion by
    assuming that the result of `find_decomposition()` for one of the
    `gunichar`s was a non-`NULL` empty string, so that iteration of the
    decomposition loop didn’t append anything to `wc_buffer`.
    
    I don’t think it’s possible for an iteration of the loop to *not* append
    anything to `wc_buffer`. Unicode characters don’t decompose to nothing.
    
    Indeed, the current code coverage for GLib says that the `if (n_wc > 0)`
    branch is always taken, and at that point in the control flow, `n_wc <=
    0` is never true.
    
    So, add an assertion to check that progress is made (i.e. `n_wc` is
    incremented by at least 1), and remove the unnecessary condition.
    
    Signed-off-by: default avatarPhilip Withnall <pwithnall@gnome.org>
    
    Helps: #1767
    05158475