Bug 209464

Summary: Several refactorings done in the MemoryPressureMonitor.cpp
Product: WebKit Reporter: Pablo Saavedra <psaavedra>
Component: WebKit2Assignee: Pablo Saavedra <psaavedra>
Status: RESOLVED FIXED    
Severity: Normal CC: aperez, bugs-noreply, clopez, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch
none
patch
none
patch
none
patch
none
patch
none
patch
none
patch none

Pablo Saavedra
Reported 2020-03-23 23:39:13 PDT
strtoull is a feature added in C++ since C11. This parses the C-string str interpreting its content as an `unsigned long long int` which is more appropriate for the size_t (unsigned integer type) variables used by the `MemoryPressureMonitor.cpp` functions in counterpoint of atoll() what returns a `long long int`.
Attachments
patch (3.27 KB, patch)
2020-03-23 23:41 PDT, Pablo Saavedra
no flags
patch (13.17 KB, patch)
2020-03-26 05:53 PDT, Pablo Saavedra
no flags
patch (13.15 KB, patch)
2020-03-26 06:13 PDT, Pablo Saavedra
no flags
patch (13.15 KB, patch)
2020-03-26 06:15 PDT, Pablo Saavedra
no flags
patch (13.15 KB, patch)
2020-03-26 06:17 PDT, Pablo Saavedra
no flags
patch (13.14 KB, patch)
2020-03-31 06:33 PDT, Pablo Saavedra
no flags
patch (13.15 KB, patch)
2020-03-31 06:41 PDT, Pablo Saavedra
no flags
Pablo Saavedra
Comment 1 2020-03-23 23:41:41 PDT
Adrian Perez
Comment 2 2020-03-24 01:33:34 PDT
Comment on attachment 394354 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=394354&action=review > Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp:87 > + low += strtoull(token, nullptr, 10); This is not doing any error checking to ensure that the parsing was successful. There are also a generic string-to-integer conversion function in WTF which you could use here: bool ok = true; low += WTF::toIntegralType<size_t, UChar>(token, strlen(token), &ok, 10); if (!ok) return 0; // Return early on error. …and so on for the rest of the conversions.
Pablo Saavedra
Comment 3 2020-03-26 05:53:48 PDT
Pablo Saavedra
Comment 4 2020-03-26 06:13:09 PDT
Pablo Saavedra
Comment 5 2020-03-26 06:15:01 PDT
Pablo Saavedra
Comment 6 2020-03-26 06:17:31 PDT
Pablo Saavedra
Comment 7 2020-03-26 06:25:58 PDT
(In reply to Adrian Perez from comment #2) > Comment on attachment 394354 [details] > patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=394354&action=review > > > Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp:87 > > + low += strtoull(token, nullptr, 10); > > This is not doing any error checking to ensure that the parsing was > successful. There are also a generic string-to-integer conversion > function in WTF which you could use here: > > bool ok = true; > low += WTF::toIntegralType<size_t, UChar>(token, strlen(token), &ok, 10); > if (!ok) return 0; // Return early on error. > > …and so on for the rest of the conversions. Thanks for your hints. I've used those in my new patch. In addition, I decided to clean up some repetitive code and fix some issues that I found running WPE in a cgroup-v2 with unified hierarchy.
Adrian Perez
Comment 8 2020-03-31 06:21:40 PDT
Comment on attachment 394601 [details] patch Thanks for the patch, having the checks for parsing numeric values in places and some of the duplicated code factored out makes me more confident in this being robust 👍️. Please check the comments before landing. It would be still nice to get rid of “strtok()” because often it is a source of footguns; but I do not have any good suggestion that would avoid writing a more formal parser… so let's just leave things as-is. View in context: https://bugs.webkit.org/attachment.cgi?id=394601&action=review > Source/WebKit/ChangeLog:34 > + getMemoryUsageWithCgroup() sighly. The name of the controller Typo: sighly → slightly > Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp:232 > + CString memoryControllerPath = CString(); You can remove the “= CString()” assignment. The default constructor will initialize the value to an empty string anyway.
Pablo Saavedra
Comment 9 2020-03-31 06:33:48 PDT
Pablo Saavedra
Comment 10 2020-03-31 06:41:52 PDT
EWS
Comment 11 2020-03-31 07:20:46 PDT
Committed r259287: <https://trac.webkit.org/changeset/259287> All reviewed patches have been landed. Closing bug and clearing flags on attachment 395031 [details].
Radar WebKit Bug Importer
Comment 12 2020-03-31 07:21:14 PDT
Note You need to log in before you can comment on or make changes to this bug.