Automatic date update in version.in
[binutils-gdb.git] / gas / sb.c
index 3b156f75d041eac6cdf141bb4fed51ada7260654..c44016a0338fe0447a46a4fd77e94eda377f134f 100644 (file)
--- a/gas/sb.c
+++ b/gas/sb.c
@@ -1,5 +1,5 @@
 /* sb.c - string buffer manipulation routines
-   Copyright (C) 1994-2017 Free Software Foundation, Inc.
+   Copyright (C) 1994-2022 Free Software Foundation, Inc.
 
    Written by Steve and Judy Chamberlain of Cygnus Support,
       sac@cygnus.com
@@ -24,9 +24,7 @@
 #include "as.h"
 #include "sb.h"
 
-#ifdef HAVE_LIMITS_H
 #include <limits.h>
-#endif
 #ifndef CHAR_BIT
 #define CHAR_BIT 8
 #endif
@@ -113,8 +111,20 @@ sb_scrub_and_add_sb (sb *ptr, sb *s)
   sb_to_scrub = s;
   scrub_position = s->ptr;
 
-  sb_check (ptr, s->len);
-  ptr->len += do_scrub_chars (scrub_from_sb, ptr->ptr + ptr->len, s->len);
+  /* do_scrub_chars can expand text, for example when replacing
+     # 123 "filename"
+     with
+     \t.linefile 123 "filename"
+     or when replacing a 'c with the decimal ascii number for c.
+     So we loop until the input S is consumed.  */
+  while (1)
+    {
+      size_t copy = s->len - (scrub_position - s->ptr);
+      if (copy == 0)
+       break;
+      sb_check (ptr, copy);
+      ptr->len += do_scrub_chars (scrub_from_sb, ptr->ptr + ptr->len, copy);
+    }
 
   sb_to_scrub = 0;
   scrub_position = 0;