Warnung: might be used uninitialized in this function gcc



  • Hallo,

    wieso bekomme ich beim GCC bei folgendem Code die Warnung:

    template <typename T>
    inline T* SafeAllocateMemory(const u_long Size)
    {
      if (!Size)
        return 0;
    
      try
      {
        return new T[Size];
      }
      catch (std::bad_alloc)
      {
        return 0;
      }
    }
    
    template <typename T>
    T** SafeAllocateMemory(const u_long Width, const u_long Height)
    {
      T **tmpData = SafeAllocateMemory<T*>(Height);
    
      // wenn nicht initialisiert, dann auch nix machen...
      if (tmpData)
      {
        for (u_long i = 0; i < Height; ++i)
          tmpData[i] = SafeAllocateMemory<T>(Width);
      }
    
      return tmpData;
    }
    

    warning: 'tmpData' might be used uninitialized in this function

    ???

    Wie bekomme ich die weg, bzw. muss ich den Code ändern damit sie gar nicht erst auftaucht?

    Danke...


Anmelden zum Antworten