summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics/eoshift0.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/intrinsics/eoshift0.c')
-rw-r--r--libgfortran/intrinsics/eoshift0.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/libgfortran/intrinsics/eoshift0.c b/libgfortran/intrinsics/eoshift0.c
index b1fbd1a516a..6152e9fccbd 100644
--- a/libgfortran/intrinsics/eoshift0.c
+++ b/libgfortran/intrinsics/eoshift0.c
@@ -131,10 +131,19 @@ eoshift0 (gfc_array_char * ret, const gfc_array_char * array,
sstride0 = sstride[0];
rptr = ret->data;
sptr = array->data;
- if (shift > 0)
- len = len - shift;
+
+ if ((shift >= 0 ? shift : -shift) > len)
+ {
+ shift = len;
+ len = 0;
+ }
else
- len = len + shift;
+ {
+ if (shift > 0)
+ len = len - shift;
+ else
+ len = len + shift;
+ }
while (rptr)
{