[gdb] Fix warning in foreach_arch selftests
[binutils-gdb.git] / ld / libdep_plugin.c
index b81364fdca598e6bc5f3817d956d164fa27047d0..453df71c15b04f2df87bdbe41382dba6028763eb 100644 (file)
@@ -1,5 +1,5 @@
 /* libdeps plugin for the GNU linker.
-   Copyright (C) 2020 Free Software Foundation, Inc.
+   Copyright (C) 2020-2022 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
@@ -99,6 +99,7 @@ get_libdeps (int fd)
   arhdr ah;
   int len;
   unsigned long mlen;
+  size_t amt;
   linerec *lr;
   enum ld_plugin_status rc = LDPS_NO_SYMS;
 
@@ -114,7 +115,10 @@ get_libdeps (int fd)
          lseek (fd, mlen, SEEK_CUR);
          continue;
        }
-      lr = malloc (sizeof (linerec) + mlen);
+      amt = mlen + sizeof (linerec);
+      if (amt <= mlen)
+       return LDPS_ERR;
+      lr = malloc (amt);
       if (!lr)
        return LDPS_ERR;
       lr->next = NULL;
@@ -139,7 +143,7 @@ str2vec (char *in)
 
   end = in + strlen (in);
   s = in;
-  while (isspace (*s)) s++;
+  while (isspace ((unsigned char) *s)) s++;
   first = s;
 
   i = 1;
@@ -163,12 +167,12 @@ str2vec (char *in)
          memmove (s, s+1, end-s-1);
          end--;
        }
-      if (isspace (*s))
+      if (isspace ((unsigned char) *s))
        {
          if (sq || dq)
            continue;
          *s++ = '\0';
-         while (isspace (*s)) s++;
+         while (isspace ((unsigned char) *s)) s++;
          if (*s)
            res[++i] = s;
        }