[PATCH] D35690: [Sanitizers] TSan allocator set errno on failure.

Dmitry Vyukov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 23 00:58:15 PDT 2017


dvyukov accepted this revision.
dvyukov added inline comments.
This revision is now accepted and ready to land.


================
Comment at: lib/tsan/tests/unit/tsan_mman_test.cc:72
     void *p2 = user_realloc(thr, pc, p, 0);
-    EXPECT_NE(p2, (void*)0);
+    EXPECT_EQ(p2, (void*)0);
   }
----------------
alekseyshl wrote:
> alekseyshl wrote:
> > dvyukov wrote:
> > > dvyukov wrote:
> > > > Is there a particular reason for this change? If not, then I would prefer to leave the current behavior. It worked for 5 years. We don't know what will happen with this one.
> > > Note: the current behavior is correct according to both POSIX, linux man pages and C: 
> > > 
> > > If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned.
> > > 
> > > If size was equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
> > Wait, that's what the man I quoted in comments: "if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr)", so I'm freeing the pointer and it seems only natural to return NULL in this case, cause what else would I return?
> > 
> > What you're saying is correct for user_realloc(thr, pc, NULL, 0) case.
> What I mean to say, it seems strange to return a dangling pointer and stdlib's realloc returns NULL in this case anyway.
> 
> user_realloc(thr, pc, NULL, 0) is tested first hand in this test.
Okay, let's try this.


https://reviews.llvm.org/D35690





More information about the llvm-commits mailing list