Commit graph

57 commits

Author SHA1 Message Date
Tomasz Wasilczyk
a1853516ff Revert "Revert "Revert "Revert "Drop all path-related methods from android::String8""""
This reverts commit 141255f30c.

Reason for revert: Attempt re-submit again

Change-Id: I0e568fdf8f7a141ee3c5d54f68530ff478a47439
2023-09-11 17:45:16 +00:00
Rhed Jao
141255f30c Revert "Revert "Revert "Drop all path-related methods from android::String8"""
This reverts commit 4b6a7c3940.

Reason for revert: b/299695302, b/299694769

Change-Id: I89c6719d23446f2f9ce24e5b75d321538b580431
2023-09-11 02:05:58 +00:00
Tomasz Wasilczyk
4b6a7c3940 Revert "Revert "Drop all path-related methods from android::String8""
This reverts commit cff2e40d19.

Reason for revert: Attempt re-submit

Change-Id: I8802b519e4ae3046858b854815ba580c7a6b965d
2023-09-08 11:03:59 -07:00
Tomasz Wasilczyk
cff2e40d19 Revert "Drop all path-related methods from android::String8"
This reverts commit b9dc1c2991.

Reason for revert: http://b/299624573

Change-Id: I0d5993295df65ec31c180b6b5a76fbe939891f45
2023-09-08 17:08:39 +00:00
Tomasz Wasilczyk
b9dc1c2991 Drop all path-related methods from android::String8
Move them to androidfw and aapt, the last users.

Bug: 295394788
Test: m checkbuild
Change-Id: I7268b88d11bf221f93efed06cfd1ee65449a2421
2023-09-08 03:07:52 +00:00
Elliott Hughes
1d98fe0d39 Lose convertToResPath to aapt.
aapt (not aapt2) is the only user.

Test: treehugger
Change-Id: Ie69f84f4f805c69f838e345b44755a316b9f9b06
2023-08-24 04:33:05 +00:00
Tomasz Wasilczyk
90af4157c5 Add String16::c_str and start using it.
This is for parity with String8::c_str and in general the first step
in transition from String8|16.string() - to make it more similar to
std::string.

Bug: 295394788
Test: mma -j
Change-Id: I6c1411bef07c761fb2fb3fb38c27801ac4cffc57
2023-08-11 19:40:34 +00:00
Eric Miao
c6ce48ef19 String8: fix infinite loop and segmentation fault in removeAll()
Bug: 290835996
Test: libutils_fuzz_string8 for several minutes

String8::removeAll() has 2 serious problems:

1. When `other` is an empty string, `removeAll()` will loop infinitely
   due to below process:

   a) with `other` being empty string `""`, find() will call strstr()
      on an empty string, which always returns `mString`, and thus
      find() always return 0 in this case
   b) with find() returns 0 for empty string, the next while loop in
      String8::removeAll() will keep loop infinitely as `index` will
      always be 0

   This CL fixes this problem by returning true if `other` is an empty
   string (i.e. `strlen(other) == 0`), this follows the logic that an
   empty string will always be found and no actual remove needs to be
   done.

2. When `other` is a NULL string, strstr() has undefined behavior. See
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf.

   This undefined behavior on Android unfortunately causes immediate
   segmentation fault as the current `strstr` implementation in bionic
   libc doesn't check `needle` being NULL, and an access to a NULL
   location is performed to check if the `needle` string is an empty
   string, and thus causes segmentation fault.

   This CL gives an error message and aborts instead of having a
   segfault, and to keep some backward compatibility.

   This CL also adds test for String8::removeAll()

Change-Id: Ie2ccee6767efe0fed476db4ec6072717198279e9
2023-07-18 16:02:07 -07:00
Biswapriyo Nath
9e25bf0136 libutils: Include limits for std::numeric_limits::max
This fixes the following error:
core/libutils/String8.cpp:316:67: error: incomplete type 'std::numeric_limits<long long unsigned int>' used in nested name specifier
  316 |         if (static_cast<size_t>(n) > std::numeric_limits<size_t>::max() - 1 ||
      |                                                                   ^~~

Change-Id: I80cdd2442e2798c37e066e3fdeee7dd5ac34b669
2022-10-21 10:26:08 +05:30
Andrei Homescu
1a867dcb6e Fix build error from signed/unsigned comparison
Bug: 224644083
Test: m
Change-Id: I9adbe1ea53193d8c59f9022754cd3e23533e54ad
2022-03-29 00:30:34 +00:00
Treehugger Robot
f34b2446bb Merge "Revert "Revert "Remove unused String8::setPathName.""" am: f9a9ee048c am: e9a9a4f071
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1771595

Change-Id: I815e30f78c4a129de8186bd1b08278024fdf01d6
2021-07-20 20:07:22 +00:00
Greg Kaiser
d03851e549 Revert "Revert "Remove unused String8::setPathName.""
This reverts commit 70d9fb63e6.

Reason for revert: Outstanding usage of this method removed internally

Change-Id: Idcc00ec261aa1d97f11e47abdb08b10a37b5d20f
Test: Local build; treehugger (which I'll manually confirm runs on the appropriate targets)
2021-07-19 20:19:44 +00:00
Greg Kaiser
2cca5cc992 Merge "Revert "Remove unused String8::setPathName."" am: 615bf4ef14 am: 01f3306b69
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1768145

Change-Id: I9856b917353e57b048eeec2d3ed6d157165e1148
2021-07-15 13:56:01 +00:00
Greg Kaiser
70d9fb63e6 Revert "Remove unused String8::setPathName."
This reverts commit c214426e0c.

Reason for revert: This is not unused; broke build internally

Change-Id: I18e8b7954256ae015ad32743fa6a75850b00913e
2021-07-15 13:33:10 +00:00
Elliott Hughes
941b1a61b0 Merge "Remove unused String8::setPathName." am: 40a0664b84 am: 5f7d548dc6
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1765465

Change-Id: If7b66e7de22107110fa595827611f1bb1a83a9dc
2021-07-14 21:48:06 +00:00
Elliott Hughes
c214426e0c Remove unused String8::setPathName.
Test: treehugger
Change-Id: Idc8d7e748b0df4ce8a26227dc73a5eef2b04244f
2021-07-13 17:20:53 -07:00
Elliott Hughes
59682761fb Check for overflow in String8::real_append.
Bug: http://b/178822418
Test: new tests
Change-Id: I73631a070ade0689441abe5645ba5a5f64a58675
2021-06-10 16:42:20 -07:00
Elliott Hughes
6182b330f2 Merge "Remove move dead code." am: acec0918e5 am: 1fc404900c am: 906a03fc49
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1677028

Change-Id: I7fb50216bcf983584f664a691321683dd79ae38d
2021-04-16 17:53:46 +00:00
Elliott Hughes
4b7b4d6d7b Remove move dead code.
Test: treehugger
Change-Id: I6a23b19d078400dfe90329a49ae1abbcb24ef2bf
2021-04-15 15:18:54 -07:00
Elliott Hughes
b996f3f512 Merge "Remove String8::toUpper()." am: 450f66bd8f am: ca3794ea68 am: 334a0b1c10
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1673886

Change-Id: Ica526ca8cb76065e4008a8dbd494beb795ea1390
2021-04-14 19:58:02 +00:00
Elliott Hughes
9434f59c17 Remove String8::toUpper().
Actually, it looks like it's only toLower() that's used, so let's remove
toUpper() separately, since it's so easy.

Test: treehugger
Change-Id: I8fae9fa513b2a34d5bd6b3f64e9305a1ee3c1ec4
2021-04-12 13:38:31 -07:00
Elliott Hughes
b546cf8c5c Merge "Remove the weird range variants of String8::toLower() and String8::toUpper()." am: 561209ee66 am: 7e7ff3635d am: 685c0c9a7f
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1670567

Change-Id: Iedb8ab438496e0fa3f6697fb18b060e3a1acbc89
2021-04-12 20:35:29 +00:00
Elliott Hughes
a858395f91 Remove the weird range variants of String8::toLower() and String8::toUpper().
I want to remove these bad ASCII-only APIs completely, but it might be
easier to remove the range variants first.

Test: treehugger
Change-Id: I4c11f959a7bd8e670708cc03281ea72e9c461ff7
2021-04-09 13:06:20 -07:00
The Android Open Source Project
7fd5f8d2bc DO NOT MERGE - Merge RP1A.201005.006
Bug: 168212094
Change-Id: I79a7517bce1c012eac2a2a7c1c2cffc5a3516eaa
Merged-In: Ia85067d4258bde4b875c832d6223db5dd26b8838
2020-10-06 04:30:21 +00:00
Steven Moreland
bad50ed24f libutils: check vsnprintf error
For encoding errors, this function will return a negative value which
causes problems down the line. Check for an error and return. Also,
integer overflows are guarded.

Bug: 161894517
Test: fuzzer test case
Change-Id: Ia85067d4258bde4b875c832d6223db5dd26b8838
Merged-In: Ia85067d4258bde4b875c832d6223db5dd26b8838
(cherry picked from commit ee22384c54)
2020-08-12 21:45:05 +00:00
Steven Moreland
0f0cb957b2 libutils: check vsnprintf error
For encoding errors, this function will return a negative value which
causes problems down the line. Check for an error and return. Also,
integer overflows are guarded.

Bug: 161894517
Test: fuzzer test case
Change-Id: Ia85067d4258bde4b875c832d6223db5dd26b8838
2020-07-28 21:43:13 +00:00
Steven Moreland
fdbc565dd5 String8: explicit int -> char cast.
Since tolower/toupper take and return integer arguments, ascii chars in
the extended range will be converted from positive int values to
negative char values. In order to silence an error here, which was added
recently with integer sanitization here, casting explicitly.

Fixes: 160831549
Test: w/ libutils_fuzz_string8
Change-Id: Iedcd6643f95f84ce662a80e38931d918a200f508
2020-07-13 23:33:25 +00:00
Steven Moreland
727a6dd5f5 String*: remove 'StaticLinkage' constructor
Unneeded.

Bug: N/A
Test: N/A
Change-Id: I3ff473d1e2fec98e47abd8abb45dd36e0a808170
2020-02-10 13:56:44 -08:00
Steven Moreland
0e19f3b4cc Remove utf32 functions.
These don't appear to be used by anything.

Bug: N/A
Test: binary inspection + code inspection
Change-Id: I6c12db26c320a66bcf6e28618c6e9f61b40d985e
2019-07-02 18:15:03 -07:00
Elliott Hughes
643268f325 Move system/core/ off NO_ERROR.
It causes trouble for Windows, and OK already exists.

Bug: N/A
Test: builds
Change-Id: Ida22fd658b0ebb259c710ba39049b07c9e495d9c
2018-10-08 11:15:52 -07:00
Yi Kong
e1731a4f2e [libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
2018-07-16 18:11:34 -07:00
Steven Moreland
241b93cfd3 libutils: Remove Static.cpp and darwin hacks.
Bug: N/A
Test: in internal master, the only libraries that reference this
  symbol are:
./prebuilts/sdk/tools/linux/bin/split-select android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/bin/aapt android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/bin/aapt2 android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/lib64/libaapt2_jni.so android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/lib64/libaapt2_jni.so android::gDarwinIsReallyAnnoying
+ VNDK libraries
Test: libutils_test

Change-Id: Id39e5ef6438e48fa225ba06dbb59902ca5b60f70
2018-03-06 17:44:08 +00:00
Steven Moreland
d21cfab244 Add missing includes.
Includes are transitively imported by <string> in String8.h + String16.h
but that include is being removed.

Test: pass
Change-Id: Ide5c011b40b4a4f031dd26ead08b5c8d5d299693
2017-03-10 09:05:30 -08:00
Mathias Agopian
22dbf3947f clean-up libutils includes
moved Foo.h as first include of Foo.cpp, and
removed redundant includes.

Made NativeHandle non virtual.


Test: run & compile
Bug: n/a

Change-Id: I37fa746cd42c9ba23aba181f84cb6c619386406a
2017-03-03 14:47:47 -08:00
Sergio Giro
502602366c Merge \"libutils/Unicode.cpp: Correct length computation and add checks for utf16->utf8\" into nyc-mr1-dev
am: 7714abac6b

Change-Id: I63e0299219dc1e50b31a88384fed7f3f43e9f86e
2016-07-11 12:22:43 +00:00
Sergio Giro
c4966a363e libutils/Unicode.cpp: Correct length computation and add checks for utf16->utf8
Inconsistent behaviour between utf16_to_utf8 and utf16_to_utf8_length
is causing a heap overflow.

Correcting the length computation and adding bound checks to the
conversion functions.

Test: ran libutils_tests
Bug: 29250543
Change-Id: I6115e3357141ed245c63c6eb25fc0fd0a9a7a2bb
2016-07-11 09:46:32 +00:00
Samuel Tan
95fd527065 libutils: remove whitespace from String8 files
Remove trailing whitespace from String8 header and
cpp files.

BUG: None
Change-Id: Ie77da3f0fbce9cdce20225ce1310cf62295179a4
2016-02-18 17:04:20 -08:00
Sergio Giro
b5a00d6b2e am e0453334: Merge "system/core: remove methods returning SharedBuffer in String8, String16"
* commit 'e045333445ab3ebb8d602d25ed750169f135baa6':
  system/core: remove methods returning SharedBuffer in String8, String16
2015-09-30 20:04:50 +00:00
Sergio Giro
282efae9c3 system/core: remove methods returning SharedBuffer in String8, String16
Towards deprecation of SharedBuffer

Change-Id: I3069837db32837bcc0f5d8f1118ccd502c9070dc
2015-09-30 15:42:02 +01:00
Sergio Giro
f777655d85 resolved conflicts for 6ee734cf to stage-aosp-master
Change-Id: Ia06c4d941d9b8828707299bb363f51fab5549897
2015-09-23 17:58:25 +01:00
Sergio Giro
d2529f2830 libutils: hide SharedBuffer by moving SharedBuffer.h to the implementation directory
Some methods in header files of classes using SharedBuffer need
to be moved to the implementation files accordingly

Change-Id: I891f3ace2b940ab219e4e449040bfed71c0547db
2015-09-23 16:22:59 +01:00
Abhishek Arya
64e2d8c0dc am 219a006f: am fc5fdc85: am e45d96d6: am 19398a71: am d34846b7: am cd407a17: am e0dce90b: Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
* commit '219a006f89a5448a9a6eeb1f37ad0088e85bd3f8':
  Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
2015-08-21 07:12:31 +00:00
Abhishek Arya
fc5fdc8568 am e45d96d6: am 19398a71: am d34846b7: am cd407a17: am e0dce90b: Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
* commit 'e45d96d6bf592f0ae20bb021ea529acc94e0cb55':
  Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
2015-08-21 06:54:21 +00:00
Abhishek Arya
d34846b70b am cd407a17: am e0dce90b: Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
* commit 'cd407a17fe326f3e18866ddddb1c747b06a45fc0':
  Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
2015-08-21 06:23:50 +00:00
Abhishek Arya
e0dce90b0d Fix compile failure after rIfe1dc0791040150132bea6884f1e6c8d31972d1b
Bug: 23290056
Change-Id: If6e22b0159de6635a8ca5305895b7718f15becc7
2015-08-20 21:55:55 -07:00
Sergio Giro
93f106b8d0 am e97682be: am a1a22b57: am e67b5848: am 4956c0fe: am 5b85b1d4: libutils: fix overflow in String8::allocFromUTF8
* commit 'e97682be0634fe773f70097bc518e5d034efe8f7':
  libutils: fix overflow in String8::allocFromUTF8
2015-08-20 22:58:19 +00:00
Sergio Giro
e67b584869 am 4956c0fe: am 5b85b1d4: libutils: fix overflow in String8::allocFromUTF8
* commit '4956c0fe1e582a8497aff34a41aeb8bf4748eef0':
  libutils: fix overflow in String8::allocFromUTF8
2015-08-20 22:28:53 +00:00
Sergio Giro
5b85b1d40d libutils: fix overflow in String8::allocFromUTF8
Patch contributed in:
https://code.google.com/p/android/issues/detail?id=182908

Bug: 23290056

(cherry picked from commit 4eeacbeec0)

Change-Id: Ife1dc0791040150132bea6884f1e6c8d31972d1b
(cherry picked from commit ebabef2752)
2015-08-18 20:52:25 +00:00
Sergio Giro
ba71601aac am 29c12755: Merge "libutils: fix overflow in String8::allocFromUTF8" into mnc-dev
* commit '29c1275519ef85fa3f30be351f19dc6e7eedbee9':
  libutils: fix overflow in String8::allocFromUTF8
2015-08-18 17:19:10 +00:00
Sergio Giro
ebabef2752 libutils: fix overflow in String8::allocFromUTF8
Patch contributed in:
https://code.google.com/p/android/issues/detail?id=182908

Bug: 23290056

(cherry picked from commit 4eeacbeec0)

Change-Id: Ife1dc0791040150132bea6884f1e6c8d31972d1b
2015-08-18 18:06:38 +01:00