bug-groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #62398] .../troff/input.cpp: argument "len" is zero in "new unsigne


From: Bjarni Ingi Gislason
Subject: [bug #62398] .../troff/input.cpp: argument "len" is zero in "new unsigned char[len]"
Date: Mon, 2 May 2022 20:54:09 -0400 (EDT)

URL:
  <https://savannah.gnu.org/bugs/?62398>

                 Summary: .../troff/input.cpp: argument "len" is zero in "new
unsigned char[len]"
                 Project: GNU troff
            Submitted by: bjarniig
            Submitted on: Tue 03 May 2022 12:54:07 AM UTC
                Category: Core
                Severity: 3 - Normal
              Item Group: Warning/Suspicious behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None

    _______________________________________________________

Details:

Subject: .../troff/input.cpp: argument "len" is zero in "new unsigned
char[len]"

  Output from gcc with option -Walloc-zero:

[...]
  CXX      src/roff/troff/input.o
In constructor 'temp_iterator::temp_iterator(const char*, int)',
    inlined from 'input_iterator* make_temp_iterator(const char*)' at
../src/roff/troff/input.cpp:3627:34:
../src/roff/troff/input.cpp:3611:31: warning: argument 1 value is zero
[-Walloc-zero]
 3611 |   base = new unsigned char[len];
      |                               ^
In file included from /usr/include/c++/11/bits/stl_iterator.h:82,
                 from /usr/include/c++/11/bits/stl_algobase.h:67,
                 from /usr/include/c++/11/vector:60,
                 from ../src/roff/troff/charinfo.h:20,
                 from ../src/roff/troff/input.cpp:31:
/usr/include/c++/11/new: In function 'input_iterator* make_temp_iterator(const
char*)':
/usr/include/c++/11/new:128:26: note: in a call to allocation function 'void*
operator new [](std::size_t)' declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW
(std::bad_alloc)
      |                          ^~~~~~~~
  CXX      src/roff/troff/mtsm.o
[...]

  The code is:

  base = new unsigned char[len];
  if (len > 0)
    memcpy(base, s, len);
  ptr = base;
  eptr = base + len;

IS THIS BETTER ?

// gcc -Walloc-zero warns when len = 0

  if (len > 0) {
    base = new unsigned char[len];
    memcpy(base, s, len);
    ptr = base;
    eptr = base + len;
  } else {
    base = 0;
    ptr = 0;
    eptr = 0;
  }

N.B.  No warning






    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?62398>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]