Genivia / ugrep-indexer

A monotonic indexer to speed up grepping by >10x (ugrep-indexer is now part of ugrep 6.0)
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
67 stars 1 forks source link

ugrep-indexer.cpp:188:8: error: 'uint64_t' does not name a type #6

Closed vt-alt closed 10 months ago

vt-alt commented 10 months ago

When building 0.9.2 on ALT Linux there is build error:

make[2]: Entering directory '/usr/src/RPM/BUILD/ugrep-indexer-0.9.2/src'
x86_64-alt-linux-g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I..  -DPLATFORM=\"x86_64-alt-linux-gnu\" -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include  -pipe -frecord-gcc-switches -Wall -fdiagnostics-color=always -fdiagnostics-color=always -g -O2 -flto=auto -c -o ugrep_indexer-ugrep-indexer.o `test -f 'ugrep-indexer.cpp' || echo './'`ugrep-indexer.cpp
ugrep-indexer.cpp:188:8: error: 'uint64_t' does not name a type
  188 | inline uint64_t modified_time(const struct stat& buf)
      |        ^~~~~~~~
ugrep-indexer.cpp:161:1: note: 'uint64_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
  160 | # include "config.h"
  +++ |+#include <cstdint>
  161 | #endif
ugrep-indexer.cpp:202:8: error: 'uint64_t' does not name a type
  202 | inline uint64_t file_size(const struct stat& buf)
      |        ^~~~~~~~
ugrep-indexer.cpp:202:8: note: 'uint64_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
ugrep-indexer.cpp: In function 'void cat(const std::string&, std::stack<Entry>&, std::vector<Entry>&, uint64_t&, uint64_t&, uint64_t&, int64_t&, int64_t&, uint64_t&, uint64_t&, bool)':
ugrep-indexer.cpp:1389:20: error: 'modified_time' was not declared in this scope
 1389 |       index_time = modified_time(buf);
      |                    ^~~~~~~~~~~~~
ugrep-indexer.cpp:1399:73: error: 'modified_time' was not declared in this scope
 1399 |             dir_entries.emplace(entry_pathname, strlen(dirent->d_name), modified_time(buf), file_size(buf));
      |                                                                         ^~~~~~~~~~~~~
ugrep-indexer.cpp:1399:93: error: 'file_size' was not declared in this scope
 1399 |             dir_entries.emplace(entry_pathname, strlen(dirent->d_name), modified_time(buf), file_size(buf));
      |                                                                                             ^~~~~~~~~
ugrep-indexer.cpp:1407:34: error: 'modified_time' was not declared in this scope
 1407 |             uint64_t file_time = modified_time(buf);
      |                                  ^~~~~~~~~~~~~
ugrep-indexer.cpp:1409:90: error: 'file_size' was not declared in this scope; did you mean 'file_time'?
 1409 |             file_entries.emplace_back(entry_pathname, strlen(dirent->d_name), file_time, file_size(buf));
      |                                                                                          ^~~~~~~~~
      |                                                                                          file_time
ugrep-indexer.cpp:1422:36: error: 'modified_time' was not declared in this scope
 1422 |               uint64_t file_time = modified_time(buf);
      |                                    ^~~~~~~~~~~~~
ugrep-indexer.cpp:1424:92: error: 'file_size' was not declared in this scope; did you mean 'file_time'?
 1424 |               file_entries.emplace_back(entry_pathname, strlen(dirent->d_name), file_time, file_size(buf));
      |                                                                                            ^~~~~~~~~
      |                                                                                            file_time
make[2]: *** [Makefile:449: ugrep_indexer-ugrep-indexer.o] Error 1
make[2]: Leaving directory '/usr/src/RPM/BUILD/ugrep-indexer-0.9.2/src'
make[1]: *** [Makefile:456: all-recursive] Error 1
make: *** [Makefile:356: all] Error 2

0.9.1 was building ok.

genivia-inc commented 10 months ago

I see. There should be a <cstdint>, but I don't see it.

I'll commit an update.

vt-alt commented 10 months ago

Thanks! (BTW, I'd suggest you to add fedora:rawhide (or alt:sisyphus) container build to GA CI, as it have fresher versions of compilers, etc. which have more checks.)

vt-alt commented 10 months ago

Build error is not fixed. You added #include <cstdint> to the line 221 but error is earlier on line 188.

vt-alt commented 10 months ago

Btw (if I move include above) there is also crash:

+ cd ugrep-indexer-0.9.3
+ bin/ugrep-indexer -I -v
free(): double free detected in tcache 2

backtrace in gdb:

(gdb) bt
#0  0x00007ffff7a0967c in ?? () from /lib64/libc.so.6
#1  0x00007ffff79ba982 in raise () from /lib64/libc.so.6
#2  0x00007ffff79a34ef in abort () from /lib64/libc.so.6
#3  0x00007ffff79a439d in ?? () from /lib64/libc.so.6
#4  0x00007ffff7a130c7 in ?? () from /lib64/libc.so.6
#5  0x00007ffff7a15401 in ?? () from /lib64/libc.so.6
#6  0x00007ffff7a17a9f in free () from /lib64/libc.so.6
#7  0x00007ffff79f2b23 in fclose () from /lib64/libc.so.6
#8  0x000055555555ceac in Stream::close (this=0x7ffffffde230) at /usr/src/RPM/BUILD/ugrep-indexer-0.9.3/src/ugrep-indexer.cpp:353
#9  Stream::~Stream (this=<optimized out>, this=<optimized out>) at /usr/src/RPM/BUILD/ugrep-indexer-0.9.3/src/ugrep-indexer.cpp:342
#10 0x00005555555647a3 in indexer (pathname=<optimized out>) at /usr/src/RPM/BUILD/ugrep-indexer-0.9.3/src/ugrep-indexer.cpp:1818
#11 0x0000555555558286 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/RPM/BUILD/ugrep-indexer-0.9.3/src/ugrep-indexer.cpp:1887
genivia-inc commented 10 months ago

The two problems should be fixed now. I've made a change so that the fclose() is followed by a NULL assignment, which should take care of the issue. That's how I normally approach the open-close pairings.

vt-alt commented 10 months ago

Thank you, now it works!

ps. Another thought, you may add -fanalyzer to new gcc (13) to get more static analysis. Current output (only warning: lines, but there also some explanations):

/usr/include/c++/13/bits/basic_string.h:1596:24: warning: leak of 'opendir (MEM[(const struct basic_string *)pathname_63(D)]._M_dataplus._M_p)' [CWE-401] [-Wanalyzer-malloc-leak]
/usr/include/c++/13/bits/basic_string.h:1060:16: warning: leak of 'opendir (MEM[(const struct basic_string *)pathname_63(D)]._M_dataplus._M_p)' [CWE-401] [-Wanalyzer-malloc-leak]
/usr/include/c++/13/bits/basic_string.h:1060:16: warning: leak of 'opendir (MEM[(const struct basic_string *)pathname_63(D)]._M_dataplus._M_p)' [CWE-401] [-Wanalyzer-malloc-leak]
ugrep-indexer.cpp:296:5: warning: use of uninitialized value '__first_4' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
ugrep-indexer.cpp:275:5: warning: use of uninitialized value 'this_7(D)' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
ugrep-indexer.cpp:275:5: warning: use of uninitialized value 'this_7(D)' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
ugrep-indexer.cpp:275:5: warning: use of uninitialized value 'this_7(D)' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
ugrep-indexer.cpp:275:5: warning: use of uninitialized value 'this_7(D)' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]

I didn't check if these aren't false positives. So this is of course not a bug report.

genivia-inc commented 10 months ago

I've used analysis before, but in this case warnings seem off to me (false positives). The opendir() is always followed by a closedir(). There is no intervening return or exception. I always mentally form a model of the code in my mind to avoid these potential issues. Note that the opendir() call keeps an internal static state, which is likely the source of this warning.