[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-serviceability-dev
Subject: [PATCH] Skip the null pointer check before calling realloc
From: Alex Henrie <alexhenrie24 () gmail ! com>
Date: 2015-11-18 19:11:13
Message-ID: ae564686e3b2797ebc4d.1447873873 () localhost ! localdomain
[Download RAW message or body]
# HG changeset patch
# User Alex Henrie <alexhenrie24@gmail.com>
# Date 1447827030 25200
# Tue Nov 17 23:10:30 2015 -0700
# Node ID ae564686e3b2797ebc4d115ce9c49aa15da964ea
# Parent 28f55851bf3890dcdaa81d64d135cf35b527b987
Skip the null pointer check before calling realloc.
"If ptr is a null pointer, realloc() shall be equivalent to malloc() for
the specified size."
http://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html
Also, sizeof(char*) is more correct here than sizeof(char**), although
in practice it doesn't make a difference.
diff --git a/src/java.instrument/share/native/libinstrument/InvocationAdapter.c \
b/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
--- a/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
+++ b/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
@@ -519,21 +519,17 @@ splitPathList(const char* str, int* path
int count = 0;
char** segments = NULL;
char* c = (char*) str;
while (*c != '\0') {
while (*c == ' ') c++; /* skip leading spaces */
if (*c == '\0') {
break;
}
- if (segments == NULL) {
- segments = (char**)malloc( sizeof(char**) );
- } else {
- segments = (char**)realloc( segments, (count+1)*sizeof(char**) );
- }
+ segments = (char**)realloc( segments, (count+1)*sizeof(char*) );
jplis_assert(segments != (char**)NULL);
segments[count++] = c;
c = strchr(c, ' ');
if (c == NULL) {
break;
}
*c = '\0';
c++;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic