8214444: Wrong strncat limits in dfa.cpp
Reviewed-by: kvn
This commit is contained in:
parent
835c863ba8
commit
a971050bff
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -50,6 +50,10 @@ using namespace std;
|
|||||||
#define strdup _strdup
|
#define strdup _strdup
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if _MSC_VER < 1900
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _INTPTR_T_DEFINED
|
#ifndef _INTPTR_T_DEFINED
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
typedef __int64 intptr_t;
|
typedef __int64 intptr_t;
|
||||||
|
@ -719,21 +719,21 @@ const char *Expr::compute_external(const Expr *c1, const Expr *c2) {
|
|||||||
|
|
||||||
// Preserve use of external name which has a zero value
|
// Preserve use of external name which has a zero value
|
||||||
if( c1->_external_name != NULL ) {
|
if( c1->_external_name != NULL ) {
|
||||||
sprintf(string_buffer, "%s", c1->as_string());
|
if( c2->is_zero() ) {
|
||||||
if( !c2->is_zero() ) {
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c1->as_string());
|
||||||
strncat(string_buffer, "+", STRING_BUFFER_LENGTH);
|
} else {
|
||||||
strncat(string_buffer, c2->as_string(), STRING_BUFFER_LENGTH);
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s+%s", c1->as_string(), c2->as_string());
|
||||||
}
|
}
|
||||||
|
string_buffer[STRING_BUFFER_LENGTH - 1] = '\0';
|
||||||
result = strdup(string_buffer);
|
result = strdup(string_buffer);
|
||||||
}
|
}
|
||||||
else if( c2->_external_name != NULL ) {
|
else if( c2->_external_name != NULL ) {
|
||||||
if( !c1->is_zero() ) {
|
if( c1->is_zero() ) {
|
||||||
sprintf(string_buffer, "%s", c1->as_string());
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c2->_external_name);
|
||||||
strncat(string_buffer, " + ", STRING_BUFFER_LENGTH);
|
|
||||||
} else {
|
} else {
|
||||||
string_buffer[0] = '\0';
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s + %s", c1->as_string(), c2->as_string());
|
||||||
}
|
}
|
||||||
strncat(string_buffer, c2->_external_name, STRING_BUFFER_LENGTH);
|
string_buffer[STRING_BUFFER_LENGTH - 1] = '\0';
|
||||||
result = strdup(string_buffer);
|
result = strdup(string_buffer);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -741,18 +741,19 @@ const char *Expr::compute_external(const Expr *c1, const Expr *c2) {
|
|||||||
|
|
||||||
const char *Expr::compute_expr(const Expr *c1, const Expr *c2) {
|
const char *Expr::compute_expr(const Expr *c1, const Expr *c2) {
|
||||||
if( !c1->is_zero() ) {
|
if( !c1->is_zero() ) {
|
||||||
sprintf( string_buffer, "%s", c1->_expr);
|
if( c2->is_zero() ) {
|
||||||
if( !c2->is_zero() ) {
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c1->_expr);
|
||||||
strncat(string_buffer, "+", STRING_BUFFER_LENGTH);
|
} else {
|
||||||
strncat(string_buffer, c2->_expr, STRING_BUFFER_LENGTH);
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s+%s", c1->_expr, c2->_expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( !c2->is_zero() ) {
|
else if( !c2->is_zero() ) {
|
||||||
sprintf( string_buffer, "%s", c2->_expr);
|
snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c2->_expr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprintf( string_buffer, "0");
|
sprintf( string_buffer, "0");
|
||||||
}
|
}
|
||||||
|
string_buffer[STRING_BUFFER_LENGTH - 1] = '\0';
|
||||||
char *cost = strdup(string_buffer);
|
char *cost = strdup(string_buffer);
|
||||||
|
|
||||||
return cost;
|
return cost;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user