Imported Upstream version 0.165
[platform/upstream/elfutils.git] / libelf / gelf_update_symshndx.c
index d2bb5bb..eb80afa 100644 (file)
@@ -1,6 +1,6 @@
 /* Update symbol information and section index in symbol table at the
    given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000, 2001, 2002, 2005, 2009, 2014, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
 
 
 int
-gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
-     Elf_Data *symdata;
-     Elf_Data *shndxdata;
-     int ndx;
-     GElf_Sym *src;
-     Elf32_Word srcshndx;
+gelf_update_symshndx (Elf_Data *symdata, Elf_Data *shndxdata, int ndx,
+                     GElf_Sym *src, Elf32_Word srcshndx)
 {
   Elf_Data_Scn *symdata_scn = (Elf_Data_Scn *) symdata;
   Elf_Data_Scn *shndxdata_scn = (Elf_Data_Scn *) shndxdata;
@@ -56,12 +52,6 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
   if (symdata == NULL)
     return 0;
 
-  if (unlikely (ndx < 0))
-    {
-      __libelf_seterrno (ELF_E_INVALID_INDEX);
-      return 0;
-    }
-
   if (unlikely (symdata_scn->d.d_type != ELF_T_SYM))
     {
       /* The type of the data better should match.  */
@@ -107,7 +97,7 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
        }
 
       /* Check whether we have to resize the data buffer.  */
-      if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Sym, &symdata_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -130,7 +120,7 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
   else
     {
       /* Check whether we have to resize the data buffer.  */
-      if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Sym, &symdata_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;