diff options
author | Tor Didriksen <tor.didriksen@oracle.com> | 2012-07-26 15:05:24 +0200 |
---|---|---|
committer | Tor Didriksen <tor.didriksen@oracle.com> | 2012-07-26 15:05:24 +0200 |
commit | 76386edb83f1146fe3704569d6b4b22241ce5985 (patch) | |
tree | 13406385bf3c6fabf58dbaf27ded8ac0101ef9a4 | |
parent | 3b954d1ddd3720e5ff6b108feff49f3bb3b446af (diff) | |
download | mariadb-git-76386edb83f1146fe3704569d6b4b22241ce5985.tar.gz |
Backport of Bug#14171740 65562: STRING::SHRINK SHOULD BE A NO-OP WHEN ALLOCED=0
-rw-r--r-- | client/sql_string.h | 10 | ||||
-rw-r--r-- | sql/sql_string.h | 10 |
2 files changed, 14 insertions, 6 deletions
diff --git a/client/sql_string.h b/client/sql_string.h index 020bf78a6de..57d4d196e8c 100644 --- a/client/sql_string.h +++ b/client/sql_string.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -195,8 +195,12 @@ public: } bool real_alloc(uint32 arg_length); // Empties old string bool realloc(uint32 arg_length); - inline void shrink(uint32 arg_length) // Shrink buffer + + // Shrink the buffer, but only if it is allocated on the heap. + inline void shrink(uint32 arg_length) { + if (!is_alloced()) + return; if (arg_length < Alloced_length) { char *new_ptr; @@ -212,7 +216,7 @@ public: } } } - bool is_alloced() { return alloced; } + bool is_alloced() const { return alloced; } inline String& operator = (const String &s) { if (&s != this) diff --git a/sql/sql_string.h b/sql/sql_string.h index e5a41352992..6d5e8c46c55 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -225,8 +225,12 @@ public: } bool real_alloc(uint32 arg_length); // Empties old string bool realloc(uint32 arg_length); - inline void shrink(uint32 arg_length) // Shrink buffer + + // Shrink the buffer, but only if it is allocated on the heap. + inline void shrink(uint32 arg_length) { + if (!is_alloced()) + return; if (arg_length < Alloced_length) { char *new_ptr; @@ -242,7 +246,7 @@ public: } } } - bool is_alloced() { return alloced; } + bool is_alloced() const { return alloced; } inline String& operator = (const String &s) { if (&s != this) |