diff options
author | David 'Digit' Turner <digit@google.com> | 2014-04-17 10:58:46 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2014-04-17 10:58:46 +0200 |
commit | e5d2516f56cbf95413941c505195f4e10aba36cd (patch) | |
tree | 4770c1e08dc5b5617124b6e23b84b988312781e7 /sources/android/crazy_linker | |
parent | 781500e9a47b3ebcb5f72942831dd77284be7a0c (diff) | |
download | ndk-e5d2516f56cbf95413941c505195f4e10aba36cd.tar.gz |
crazy_linker: Fix IsSystemLibrary() implementation.
Use strrchr() instead of strchr() to really find the basename of
the library path.
+ Augment unit test to catch regressions.
Thanks to Wei James for finding this (https://codereview.appspot.com/87480043/)
Change-Id: Iafae4606241324eb2d47007157ced84b780a3ca8
Diffstat (limited to 'sources/android/crazy_linker')
-rw-r--r-- | sources/android/crazy_linker/src/crazy_linker_system.cpp | 2 | ||||
-rw-r--r-- | sources/android/crazy_linker/src/crazy_linker_system_unittest.cpp | 25 |
2 files changed, 19 insertions, 8 deletions
diff --git a/sources/android/crazy_linker/src/crazy_linker_system.cpp b/sources/android/crazy_linker/src/crazy_linker_system.cpp index fde5053b1..517915e7f 100644 --- a/sources/android/crazy_linker/src/crazy_linker_system.cpp +++ b/sources/android/crazy_linker/src/crazy_linker_system.cpp @@ -96,7 +96,7 @@ bool IsSystemLibrary(const char* lib_name) { "libEGL.so", "libGLESv1_CM.so", "libGLESv2.so", "libGLESv3.so", "libOpenMAXAL.so", "libOpenSLES.so", }; const size_t kSize = sizeof(kSystemLibs) / sizeof(kSystemLibs[0]); - const char* base_name = ::strchr(lib_name, '/'); + const char* base_name = ::strrchr(lib_name, '/'); if (!base_name) base_name = lib_name; else diff --git a/sources/android/crazy_linker/src/crazy_linker_system_unittest.cpp b/sources/android/crazy_linker/src/crazy_linker_system_unittest.cpp index 632cca477..92db64c6f 100644 --- a/sources/android/crazy_linker/src/crazy_linker_system_unittest.cpp +++ b/sources/android/crazy_linker/src/crazy_linker_system_unittest.cpp @@ -44,13 +44,24 @@ TEST(System, IsSystemLibrary) { static const struct { const char* name; bool success; - } kData[] = {{"libEGL.so", true}, {"libGLESv1_CM.so", true}, - {"libGLESv1.so", false}, {"libGLESv2.so", true}, - {"libOpenMAXAL.so", true}, {"libOpenSLES.so", true}, - {"libandroid.so", true}, {"libc.so", true}, - {"libdl.so", true}, {"libjnigraphics.so", true}, - {"libm.so", true}, {"libstdc++.so", true}, - {"libstlport.so", false}, {"libz.so", true}, }; + } kData[] = { + {"libEGL.so", true}, + {"libGLESv1_CM.so", true}, + {"libGLESv1.so", false}, + {"libGLESv2.so", true}, + {"libOpenMAXAL.so", true}, + {"libOpenSLES.so", true}, + {"libandroid.so", true}, + {"libc.so", true}, + {"libdl.so", true}, + {"libjnigraphics.so", true}, + {"libm.so", true}, + {"libstdc++.so", true}, + {"libstlport.so", false}, + {"libz.so", true}, + {"/system/lib/libc.so", true}, + {"/system/libc.so/libfoo.so", false}, + }; for (size_t n = 0; n < ARRAY_LEN(kData); ++n) { TEST_TEXT << "Checking " << kData[n].name; EXPECT_EQ(kData[n].success, IsSystemLibrary(kData[n].name)); |