[PATCH] D114337: Support Windows

Danila Malyutin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 25 05:34:36 PST 2021


danilaml added inline comments.


================
Comment at: lnt/testing/profile/cPerf.cpp:154
+  while (c != EOF) {
+    if ((unsigned)(p - bufptr) > (size - 1)) {
+      size = size + 128;
----------------
kpdev42 wrote:
> danilaml wrote:
> > Why cast to `unsigned`? What if `size == 0`?
> Updated to ssize_t. 
> Note size = 0 must be provided only with lineprt = nullptr and then size is 128 after allocating bufptr. The behavior is undefined for non null lineprt and size = 0. Anyway, we have no such case here.
If it's the behaviour of the POSIX `getline` this is trying to emulate, then I guess this is fine.


================
Comment at: lnt/testing/profile/cPerf.cpp:405
       ssize_t Len = getline(&Line, &LineLen, Stream);
       if (Len == -1)
         break;
----------------
kpdev42 wrote:
> danilaml wrote:
> > I think there is a potential mem leak here, but that's not critical.
> Please look at the code  `if (Line)  free(Line);`  below.
>From the quick glance it looks like if `realloc` succeeds once inside the added `getline` function but fails the second time, `-1` is returned with `lineptr` still pointing to the old non-realloced buffer, so there will potentially be a double free as well. I might be reading it wrong however.


Repository:
  rLNT LNT

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114337/new/

https://reviews.llvm.org/D114337



More information about the llvm-commits mailing list