aboutsummaryrefslogtreecommitdiffstats
path: root/Str.c
diff options
context:
space:
mode:
Diffstat (limited to 'Str.c')
-rw-r--r--Str.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/Str.c b/Str.c
index ab083d2..03e0950 100644
--- a/Str.c
+++ b/Str.c
@@ -69,7 +69,7 @@ Strnew_charp(const char *p)
return Strnew();
x = GC_MALLOC(sizeof(struct _Str));
n = strlen(p) + 1;
- if (n < 0 || n > STR_SIZE_MAX)
+ if (n <= 0 || n > STR_SIZE_MAX)
n = STR_SIZE_MAX;
x->ptr = GC_MALLOC_ATOMIC(n);
x->area_size = n;
@@ -206,14 +206,14 @@ Strcat_charp_n(Str x, const char *y, int n)
if (n < 0)
n = STR_SIZE_MAX - 1;
newlen = x->length + n + 1;
- if (newlen < 0 || newlen > STR_SIZE_MAX) {
+ if (newlen <= 0 || newlen > STR_SIZE_MAX) {
newlen = STR_SIZE_MAX;
n = newlen - x->length - 1;
}
if (x->area_size < newlen) {
char *old = x->ptr;
- newlen = newlen * 3 / 2;
- if (newlen < 0 || newlen > STR_SIZE_MAX)
+ newlen += newlen / 2;
+ if (newlen <= 0 || newlen > STR_SIZE_MAX)
newlen = STR_SIZE_MAX;
x->ptr = GC_MALLOC_ATOMIC(newlen);
x->area_size = newlen;
@@ -256,10 +256,10 @@ Strgrow(Str x)
{
char *old = x->ptr;
int newlen;
- newlen = x->area_size * 6 / 5;
+ newlen = x->area_size + x->area_size / 5;
if (newlen == x->area_size)
newlen += 2;
- if (newlen < 0 || newlen > STR_SIZE_MAX) {
+ if (newlen <= 0 || newlen > STR_SIZE_MAX) {
newlen = STR_SIZE_MAX;
if (x->length + 1 >= newlen)
x->length = newlen - 2;