Page MenuHomePhabricator

Support Windows
ClosedPublic

Authored by kpdev42 on Sun, Nov 21, 6:16 AM.

Details

Summary

After this patch LNT can be installed on Windows with preinstalled C++ compiler, e.g. Microsoft Visual Studio.

OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg

Diff Detail

Repository
rLNT LNT

Event Timeline

kpdev42 created this revision.Sun, Nov 21, 6:16 AM
kpdev42 requested review of this revision.Sun, Nov 21, 6:16 AM
danilaml added inline comments.Sun, Nov 21, 7:35 AM
lnt/testing/profile/cPerf.cpp
63

Would it work with lean and mean macro defined? It's preferable, if it would.

141

shouldn't it return ssize_t?

155

Why cast to unsigned? What if size == 0?

408

I think there is a potential mem leak here, but that's not critical.

kpdev42 updated this revision to Diff 389738.Thu, Nov 25, 4:45 AM

Addressing review

kpdev42 marked 4 inline comments as done.Thu, Nov 25, 4:47 AM
kpdev42 added inline comments.
lnt/testing/profile/cPerf.cpp
63

Sure, I have updated the patch.

141

Thanks! Fixed now.

155

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.

408

Please look at the code if (Line) free(Line); below.

danilaml added inline comments.Thu, Nov 25, 5:34 AM
lnt/testing/profile/cPerf.cpp
155

If it's the behaviour of the POSIX getline this is trying to emulate, then I guess this is fine.

408

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.

slydiman added inline comments.Thu, Nov 25, 9:42 AM
lnt/testing/profile/cPerf.cpp
408

Please look at the example on Microsoft doc https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/realloc

// Reallocate and show new size:
oldbuffer = buffer;     // save pointer in case realloc fails
if ( (buffer = realloc(buffer, size + (1000 * sizeof(long)) ) ) == NULL)
{
   free(oldbuffer);  // free original block
   exit(1);
}

So everything is correct according to this example.

danilaml added inline comments.Thu, Nov 25, 11:28 AM
lnt/testing/profile/cPerf.cpp
408

I don't see it. The situation I'm talking about is akin to:

oldbuffer = buffer;     // save pointer in case realloc fails
if ( (buffer = realloc(buffer, size + (1000 * sizeof(long)) ) ) == NULL) // succeeds 
{
   free(oldbuffer); 
   exit(1);
}
// oldbuffer is pointing to the old, potentially freed buffer, buffer != oldbuffer
size += ...
if ( (buffer = realloc(buffer, size + (1000 * sizeof(long)) ) ) == NULL) // fails
{
   free(oldbuffer);  // buffer is not freed, oldbuffer is freed the second time
}

Here, oldbuffer would

slydiman added inline comments.Thu, Nov 25, 2:12 PM
lnt/testing/profile/cPerf.cpp
157

It seems p may be invalid after realloc().

kpdev42 updated this revision to Diff 390042.Fri, Nov 26, 6:51 AM
kpdev42 marked 4 inline comments as done.

I have fixed and optimized the function getline() with all the comments in mind

This revision is now accepted and ready to land.Fri, Nov 26, 7:11 AM
This revision was automatically updated to reflect the committed changes.