From f24a5dfd45b0c0a7947c5f6e9e13815908eb76f3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 9 Mar 2019 04:27:04 -0500 Subject: [PATCH] More efficient xml parsing --- native/jni/magiskhide/proc_monitor.cpp | 30 ++++++++++++++------------ native/jni/utils/file.cpp | 5 +++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/native/jni/magiskhide/proc_monitor.cpp b/native/jni/magiskhide/proc_monitor.cpp index 6b6a55322..a2bcf125a 100644 --- a/native/jni/magiskhide/proc_monitor.cpp +++ b/native/jni/magiskhide/proc_monitor.cpp @@ -99,27 +99,29 @@ static bool parse_packages_xml(string_view s) { return true; /* */ char *start = (char *) s.data(); - start[s.length() - 2] = '\0'; /* Remove trailing '>' */ + start[s.length() - 1] = '\0'; /* Remove trailing '>' */ start += 9; /* Skip ' &fn, boo while ((read = getline(&buf, &len, fp)) >= 0) { start = buf; if (trim) { - while (buf[read - 1] == '\n' || buf[read - 1] == ' ') - buf[read-- - 1] = '\0'; + while (read && (buf[read - 1] == '\n' || buf[read - 1] == ' ')) + --read; + buf[read] = '\0'; while (*start == ' ') ++start; }