Open Bug 1683778 Opened 5 years ago Updated 5 years ago

warning: array subscript 1 is outside array bounds of ‘nsTArray<ns*>' in mailnews

Categories

(MailNews Core :: Backend, defect)

x86_64
Linux
defect

Tracking

(Not tracked)

People

(Reporter: aceman, Unassigned)

Details

When compiling Thunderbird with GCC 10 I get several warnings of this class:

In file included from dist/include/nsTArray.h:3246,
from dist/include/msgIStructuredHeaders.h:14,
from dist/include/nsIMsgCompFields.h:10,
from dist/include/nsIMsgCompose.h:14,
from mailnews/compose/src/nsMsgCompose.h:9,
from mailnews/compose/src/nsMsgCompose.cpp:6:
dist/include/nsTArray-inl.h: In member function ‘nsresult nsMsgCompose::LookupAddressBook(nsTArray<nsMsgRecipient> (&)[3])’:
dist/include/nsTArray-inl.h:304:19: warning: array subscript 1 is outside array bounds of ‘nsTArray<nsMsgMailList> [1]’ [-Warray-bounds]
304 | mHdr->mLength = 0;
| ~~~~~~~~~~~~~~^~~
mailnews/compose/src/nsMsgCompose.cpp:4535:27: note: while referencing ‘mailListProcessed’
4535 | nsTArray<nsMsgMailList> mailListProcessed;
| ^~~~~~~~~~~~~~~~~

I am wondering what the problem is here.

Flags: needinfo?(mkmelin+mozilla)
Flags: needinfo?(ishikawa)

I don't know exactly, but I bet it has something to do with this: https://searchfox.org/comm-central/rev/c4336ca990fc2c70be11c7554f24bdaa40936013/mailnews/compose/src/nsMsgCompose.h#94-96

The whole concept of typedeffing an RecipientsArray seems rather weird. Ripping that out probably fixes the warning in the process.

Flags: needinfo?(mkmelin+mozilla)

Strangely, I did not see the warning. But maybe my source is too old (about a week old).
My gcc may not match yours.

My environment.

[a] I have a source tree about a week old.
Excerpt from hg log | head -500
....
changeset: 31285:6ed5bceb4661 <--- this is before I applied my local patches.
tag: qparent
fxtree: comm
user: Richard Marti <richard.marti@gmail.com>
date: Tue Dec 15 15:12:32 2020 +0100
summary: Bug 1681010 - Follow-up: Fix the search glass color on macOS. r=aleca
...

[b] My gcc version is as follows.

ishikawa@ip030:/NREF-COMM-CENTRAL/mozilla$ gcc --version
gcc (Debian 10.2.1-1) 10.2.1 20201207
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


[3] The compile command for nsMsgCompose.o

I have no idea why my compilation uses -Wno-error=array-bounds. I simply ran |mach configure|

  • No warning with the following line.
  • I removed -Wno-error-array=bounds. No warning (obviously?).
  • I inserted -Warray-bounds instead. Still no warning ...

/usr/bin/ccache /usr/bin/g++-10 -std=gnu++17 -o nsMsgCompose.o -c -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/stl_wrappers -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/system_wrappers -include /NEW-SSD/NREF-COMM-CENTRAL/mozilla/config/gcc_hidden.h -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -DDEBUG=1 -DOS_POSIX=1 -DOS_LINUX=1 -DMOZ_HAS_MOZGLUE -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -DSTATIC_EXPORTABLE_JS_API -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/mailnews/compose/src -I/NEW-SSD/moz-obj-dir/objdir-tb3/comm/mailnews/compose/src -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/dom/base -I/NEW-SSD/moz-obj-dir/objdir-tb3/ipc/ipdl/_ipdlheaders -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/ipc/chromium/src -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/ipc/glue -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/include -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/include/nspr -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/include/nss -fPIC -DMOZILLA_CLIENT -include /NEW-SSD/moz-obj-dir/objdir-tb3/mozilla-config.h -Wall -Wempty-body -Wignored-qualifiers -Woverloaded-virtual -Wpointer-arith -Wsign-compare -Wtype-limits -Wunreachable-code -Wwrite-strings -Wno-invalid-offsetof -Wc++2a-compat -Wduplicated-cond -Wimplicit-fallthrough -Wunused-function -Wunused-variable -Wno-error=maybe-uninitialized -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=coverage-mismatch -Wno-error=free-nonheap-object -Wno-multistatement-macros -Wno-error=class-memaccess -Wno-error=deprecated-copy -Wformat -Wformat-overflow=2 -Wno-psabi -fno-sized-deallocation -fno-aligned-new -fno-builtin-strlen -Wl,--gdb-index -Dfdatasync=fdatasync -DDEBUG_4GB_CHECK -DUSEHELGRIND=1 -DUSEVALGRIND=1 -DDEBUG -g -gsplit-dwarf -Werror=sign-compare -Werror=unused-result -Werror=unused-variable -Werror=format -fuse-ld=gold -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -pthread -pipe -g -g -Og -fvar-tracking -gdwarf-4 -fvar-tracking-assignments -freorder-blocks -fno-omit-frame-pointer -funwind-tables -MD -MP -MF .deps/nsMsgCompose.o.pp -fdiagnostics-color /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/mailnews/compose/src/nsMsgCompose.cpp

Flags: needinfo?(ishikawa)

(In reply to ISHIKAWA, Chiaki from comment #2)

Strangely, I did not see the warning. But maybe my source is too old (about a week old).
My gcc may not match yours.

My environment.

[a] I have a source tree about a week old.

I am refreshing my source tree to the latest.

[3] The compile command for nsMsgCompose.o

I have no idea why my compilation uses -Wno-error=array-bounds. I simply ran |mach configure|

This was too much of a simplification.
Actually, I pass the following as part of CFLAGS and CXXFLAGS environment variables during |mach configure|.
"-Werror=unused-result -Werror=format"
Then I pass the following as part of CFLAGS and CXXFLAGS env. variables during |mach build|.
"-Werror -Wsign-compare -Wunused-result -Wunused-variable -Wformat"

Let me check if I encounter your warning with the latest source tree. (However, I apply a few dozen patches for
local build. That may do away the warning you see without my intending to do so.)

It also happens at other places like:
In file included from dist/include/nsTArray.h:3246,
from dist/include/nsIMsgFolder.h:34,
from dist/include/nsMsgDBFolder.h:11,
from mailnews/imap/src/nsImapMailFolder.h:10,
from mailnews/imap/src/nsImapMailFolder.cpp:10:
dist/include/nsTArray-inl.h: In member function ‘virtual nsresult nsImapMailFolder::UpdateImapMailboxInfo(nsIImapProtocol*, nsIMailboxSpec*)’:
dist/include/nsTArray-inl.h:304:19: warning: array subscript 1 is outside array bounds of ‘nsTArray<unsigned int> [1]’ [-Warray-bounds]
304 | mHdr->mLength = 0;
| ~~~~~~~~~~~~~~^~~
mailnews/imap/src/nsImapMailFolder.cpp:2408:22: note: while referencing ‘keysToDelete’
2408 | nsTArray<nsMsgKey> keysToDelete;
| ^~~~~~~~~~~~

But there are also occurences in m-c code:
dist/include/nsTArray-inl.h:644:26: warning: array subscript 1 is outside array bounds of ‘nsTArray<mozilla::a11y::ProxyAccessible*> [1]’ [-Warray-bounds]
644 | aOther.mHdr->mLength = 0;
| ~~~~~~~~~~~~~~~~~~~~~^~~
mozilla/accessible/ipc/other/ProxyAccessible.cpp:84:32: note: while referencing ‘targets’
84 | nsTArray<ProxyAccessible*> targets(targetCount);
2:08.18 | ^~~~~~~

Really strange. I updated the source trees, M-C and C-C yesterday.
I don't see the error during my local compilation.
Aceman, what exactly is your GCC's version?

Mine is:
$ g++ --version
g++ (Debian 10.2.1-1) 10.2.1 20201207
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I am not sure, but Debian might have applied local patches to gcc.

Also, it is a mystery why the particular compilation options for nsMsgCompose.cpp does not include -Warray-bounds
in my local build. I triggered a single compilation of that file by touching the file.:

gmake[4]: Entering directory '/NEW-SSD/moz-obj-dir/objdir-tb3/comm/mailnews/compose/src'
comm/mailnews/compose/src/nsMsgCompose.o
/usr/bin/ccache /usr/bin/g++-10 -std=gnu++17 -o nsMsgCompose.o -c  -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/stl_wrappers -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/system_wrappers -include /NEW-SSD/NREF-COMM-CENTRAL/mozilla/config/gcc_hidden.h -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -DDEBUG=1 -DOS_POSIX=1 -DOS_LINUX=1 -DMOZ_HAS_MOZGLUE -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -DSTATIC_EXPORTABLE_JS_API -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/mailnews/compose/src -I/NEW-SSD/moz-obj-dir/objdir-tb3/comm/mailnews/compose/src -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/dom/base -I/NEW-SSD/moz-obj-dir/objdir-tb3/ipc/ipdl/_ipdlheaders -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/ipc/chromium/src -I/NEW-SSD/NREF-COMM-CENTRAL/mozilla/ipc/glue -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/include -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/include/nspr -I/NEW-SSD/moz-obj-dir/objdir-tb3/dist/include/nss -fPIC -DMOZILLA_CLIENT -include /NEW-SSD/moz-obj-dir/objdir-tb3/mozilla-config.h -Wall -Wempty-body -Wignored-qualifiers -Woverloaded-virtual -Wpointer-arith -Wsign-compare -Wtype-limits -Wunreachable-code -Wwrite-strings -Wno-invalid-offsetof -Wc++2a-compat -Wduplicated-cond -Wimplicit-fallthrough -Wunused-function -Wunused-variable -Wno-error=maybe-uninitialized -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=coverage-mismatch -Wno-error=free-nonheap-object -Wno-multistatement-macros -Wno-error=class-memaccess -Wno-error=deprecated-copy -Wformat -Wformat-overflow=2 -Wno-psabi -fno-sized-deallocation -fno-aligned-new -fno-builtin-strlen -Wl,--gdb-index -Dfdatasync=fdatasync -DDEBUG_4GB_CHECK -DUSEHELGRIND=1 -DUSEVALGRIND=1 -DDEBUG -g -gsplit-dwarf -Werror=sign-compare -Werror=unused-result -Werror=unused-variable -Werror=format -fuse-ld=gold -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -pthread -pipe -g -g -Og -fvar-tracking -gdwarf-4 -fvar-tracking-assignments -freorder-blocks -fno-omit-frame-pointer -funwind-tables  -MD -MP -MF .deps/nsMsgCompose.o.pp  -fdiagnostics-color  /NEW-SSD/NREF-COMM-CENTRAL/mozilla/comm/mailnews/compose/src/nsMsgCompose.cpp
gmake[4]: Entering directory '/NEW-SSD/moz-obj-dir/objdir-tb3/comm/mailnews/db/mork'
gmake[4]: Nothing to be done for 'target-objects'.

I see -Wno-error=array-bounds instead.
There were no warnings, and even after I changed the compiler option, -Wno-error=array-bounds, manually to -Warray-bounds and reinvoked the compilation, I didn't see the warning.

You might want to post the exact compiler options used for nsMsgCompose.cpp in your build.
Other options I use might trigger or hide the issue.

Just a data point from a Debian user who installs some packages from testing repository for local build and testing.

Flags: needinfo?(acelists)

Thanks, mine is gcc 10.2.0. I do not add any special flags to affect warnings in mozconfig.

You seem to run ccache directly from the command line? Also may those "/usr/bin/g++-10 -std=gnu++17" arguments affect your compile flags or the behaviour? I do not know if the compiler uses gnu 17 C++ version, I get what the mozilla build system sets.

Flags: needinfo?(acelists)

(In reply to :aceman from comment #6)

Thanks, mine is gcc 10.2.0. I do not add any special flags to affect warnings in mozconfig.

I am not sure if the difference in the 0.0.1 position makes a difference. Mine is 10.2.1.

You seem to run ccache directly from the command line? Also may those "/usr/bin/g++-10 -std=gnu++17" arguments affect your compile flags or the behaviour? I do not know if the compiler uses gnu 17 C++ version, I get what the mozilla build system sets.

When I ran the compiler manually as I noted, I took out ccache invocation, but that would have produced a warning if there was any.
To be honest, I have not tinkered with the command options other than adding the following.:

Actually, I pass the following as part of CFLAGS and CXXFLAGS environment variables during |mach configure|.
"-Werror=unused-result -Werror=format"
Then I pass the following as part of CFLAGS and CXXFLAGS env. variables during |mach build|.
"-Werror -Wsign-compare -Wunused-result -Wunused-variable -Wformat"

Everything else is set by running |mach configure|. So I have no idea how configure inserts "-std=gnu++17" for my local build.
This is all magic as far as I know. I have to trust |mach configure| to do the job. :-)

You need to log in before you can comment on or make changes to this bug.