0

こんにちは、malloc の使用に問題があります。エラー コードは 3096 です。

malloc.c:3096: sYSMALLOc: アサーション `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2]))) - __builtin_offsetof (struct malloc_chunk、fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~(((2 * (sizeof) (size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' が失敗しました。アボート

コード:

    char    *malloc_tab(char *str)
    {
      if ((str = malloc(1024)) == NULL)
        return (NULL);
      return (str);
    }

    int     *malloc_tab_int(int *str)
    {
      int   i;

      i = 0;
      if ((str = malloc(1024)) == NULL)
        return (NULL);
      while (i != 1024)
        {
          str[i] = 0;
          i = i + 1;
        }
      return (str);
    }

char    **malloc_dim_tab(char **str)
{
  int   y;

  y = 0;
  if ((str = malloc(1024 * sizeof(*str))) == NULL)
    return (NULL);
  while (y < 200)
    {
      if ((str[y] = malloc(1024 * sizeof(**str))) == NULL)
        return (NULL);
      y = y + 1;
    }
  return (str);
}

助けてください!

4

2 に答える 2

0

次のようなエラー コード :"malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) ") は、コード内の次の malloc() の前に、現在の malloc() 書き込み/読み取りオーバーフローが原因で発生することを意味します。

あなたがやってみることができます: str = malloc(1024 * sizeof(char *))

于 2013-07-09T09:19:19.147 に答える