Skip to content

don't cast away constness#1865

Merged
davisking merged 1 commit into
davisking:masterfrom
tdp2110:tom/var
Aug 23, 2019
Merged

don't cast away constness#1865
davisking merged 1 commit into
davisking:masterfrom
tdp2110:tom/var

Conversation

@tdp2110
Copy link
Copy Markdown
Contributor

@tdp2110 tdp2110 commented Aug 23, 2019

there was no actual harm here: the unconsting was consted up by the member (but it needn't have been had the member been pointer to non-const).

generally speaking, reinterpret_cast is better than C-style casting because it cannot cast away constness.

@davisking
Copy link
Copy Markdown
Owner

Cool, thanks for the PR :)

@davisking davisking merged commit a81fd0c into davisking:master Aug 23, 2019
@tdp2110
Copy link
Copy Markdown
Contributor Author

tdp2110 commented Aug 23, 2019

btw, check out clang-tidy if you haven't already. I ran it on this repo and it showed a couple of things, like potential nullptr dereference in entropy_decoder_model_kernel_5.h on node *n = temp->child_context; (line 356). I briefly thought about fixing it, but wasn't sure how :)

@davisking
Copy link
Copy Markdown
Owner

I’m not super concerned. That code is ancient and extremely well used without any issues.

@tdp2110
Copy link
Copy Markdown
Contributor Author

tdp2110 commented Aug 26, 2019

I don't doubt it. Static analyzers are notorious for false positives too.

This one was from symbolic analysis though (but might still be impossible):

/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:430:41: warning: Access to field 'symbol' results in a dereference of a null pointer (loaded from variable 'n') [clang-analyzer-core.NullDereference]
                        if (is_excluded(n->symbol) == false)
                                        ^
/home/tom/projects/dlib/dlib/data_io/image_dataset_metadata.cpp:47:13: note: Calling 'create_image_metadata_stylesheet_file'
            create_image_metadata_stylesheet_file(filename);
            ^
/home/tom/projects/dlib/dlib/data_io/image_dataset_metadata.cpp:29:17: note: Assuming 'pos' is equal to 'npos'
            if (pos != std::string::npos)
                ^
/home/tom/projects/dlib/dlib/data_io/image_dataset_metadata.cpp:29:13: note: Taking false branch
            if (pos != std::string::npos)
            ^
/home/tom/projects/dlib/dlib/data_io/image_dataset_metadata.cpp:33:13: note: Taking false branch
            if (!fout)
            ^
/home/tom/projects/dlib/dlib/data_io/image_dataset_metadata.cpp:36:21: note: Calling 'get_decoded_string'
            fout << get_decoded_string();
                    ^
/home/tom/projects/dlib/dlib/data_io/image_dataset_metadata.cpp:397:13: note: Calling 'compress_stream_kernel_1::decompress'
            compressor.decompress(sin,sout);
            ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:191:9: note: Loop condition is true.  Entering loop body
        while (true)
        ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:194:13: note: Taking false branch
            if (count == 20000)
            ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:207:17: note: Assuming 'symbol' is equal to 'eof_symbol'
            if (symbol != eof_symbol)
                ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:207:13: note: Taking false branch
            if (symbol != eof_symbol)
            ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:226:17: note: Calling 'entropy_decoder_model_kernel_5::decode'
                model.decode(symbol); byte2 = static_cast<unsigned char>(symbol);
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:385:9: note: Taking false branch
        if (something_is_excluded())
        ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:388:9: note: Loop condition is true.  Entering loop body
        while (true)
        ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:391:13: note: Taking true branch
            if (space_left())
            ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:395:17: note: Taking false branch
                if (total_count > 0)
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:511:21: note: Taking false branch
                    if (new_node != 0)
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:524:21: note: Left side of '&&' is true
                if (cur == 0 && local_order < order)
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:524:17: note: Taking true branch
                if (cur == 0 && local_order < order)
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:531:17: note: Null pointer value stored to field 'child_context'
                new_node->child_context = 0;
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:534:17: note: Calling 'entropy_decoder_model_kernel_5::push'
                push(new_node,temp);
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:723:5: note: Returning without writing to 'n->child_context'
    }
    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:534:17: note: Returning from 'entropy_decoder_model_kernel_5::push'
                push(new_node,temp);
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:539:17: note: Taking false branch
                if (temp != root)
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:556:17: note: Taking false branch
                if (cur == 0)
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:561:17: note:  Execution continues on line 576
                break;                          
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:577:9: note: Loop condition is true.  Entering loop body
        while (stack_size > 0)
        ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:579:13: note: Calling 'entropy_decoder_model_kernel_5::pop'
            pop(n,nc);        
            ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:742:5: note: Returning without writing to 'n->child_context'
    }
    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:579:13: note: Returning from 'entropy_decoder_model_kernel_5::pop'
            pop(n,nc);        
            ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:584:13: note: Taking false branch
            if (nc->total)
            ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:606:13: note: Loop condition is false. Execution continues on line 577
            while (nc->total > 10000)
            ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:577:9: note: Loop condition is false. Execution continues on line 577
        while (stack_size > 0)
        ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:226:17: note: Returning from 'entropy_decoder_model_kernel_5::decode'
                model.decode(symbol); byte2 = static_cast<unsigned char>(symbol);
                ^
/home/tom/projects/dlib/dlib/data_io/../compress_stream/compress_stream_kernel_1.h:227:17: note: Calling 'entropy_decoder_model_kernel_5::decode'
                model.decode(symbol); byte3 = static_cast<unsigned char>(symbol);
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:385:9: note: Taking false branch
        if (something_is_excluded())
        ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:388:9: note: Loop condition is true.  Entering loop body
        while (true)
        ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:391:13: note: Taking true branch
            if (space_left())
      1 warning generated.

      ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:395:21: note: Assuming 'total_count' is > 0
                if (total_count > 0)
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:395:17: note: Taking true branch
                if (total_count > 0)
                ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:398:25: note: Assuming 'total_count' is <= 10000
                    if (total_count > 10000)
                        ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:398:21: note: Taking false branch
                    if (total_count > 10000)
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:404:21: note: Taking false branch
                    if (something_is_excluded())
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:426:21: note: 'n' initialized to a null pointer value
                    node* n = temp->child_context;
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:428:21: note: Loop condition is true.  Entering loop body
                    while (true)
                    ^
/home/tom/projects/dlib/dlib/data_io/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:430:41: note: Access to field 'symbol' results in a dereference of a null pointer (loaded from variable 'n')
                        if (is_excluded(n->symbol) == false)

@davisking
Copy link
Copy Markdown
Owner

davisking commented Aug 31, 2019 via email

@tdp2110
Copy link
Copy Markdown
Contributor Author

tdp2110 commented Sep 7, 2019

Unfortunately no, I only have the analyzer output.

bkornel added a commit to bkornel/dlib that referenced this pull request Sep 18, 2019
* Fixed compiler warnings

* Include the Intel MKL's iomp dll in the output folder to reduce confusino for windows users.

* Fixed build error in newer clang on OpenBSD.

* Fixed constness for lapack functions (davisking#1737)

* disable annoying warning

* Fixed global_function_search's initialization being wrong if explicitly
given an empty list of initial function evaluations.

* Suppress compiler warnings

* Make things work in visual studio.

* fix some pedantic warnings (davisking#1756)

* fix some pedantic warnings

* remove unneeded assert

* more pedantic silencing (davisking#1763)

* prevent GCC from complaining about this unused parameter

* Even more warning silencing (davisking#1766)

These warnings occurred when building the semantic segmentation
examples

* iEnsures DLIB_FALLTHROUGH macro is only set for GCC>=7 (davisking#1770)

* Feature/upgrade libjpeg (davisking#1769)

* Upgrades dlib's included libjpeg to version 8d

* Overloads load_jpeg to read from memory buffer

* Removes "__inline__" define in jconfig, broke VC build

* Changes buffer size type to size_t

* Adds a comprehensive error message when jpeg loading fails.

* Disable use of non-memory based backing store in libjpeg.  This fixes
libjpeg not being able to open some types of jpeg file.

* Stop building parts of libjpeg we don't need.

* Add input_grayscale_image_pyramid, issue davisking#354 (davisking#1761)

Add input_grayscale_image_pyramid

* Added methods for getting keyboard and mouse clicks to image_window's pyhton API.

* Fixed pytest broken dependencies

* Fix python setup warnings

* Revert "Fixed pytest broken dependencies"

Apparently pytest is still sort of busted.

This reverts commit 5e63d01.

*  Fix setting a point's y coordinate changes x instead (Python bindings) (davisking#1795)

* Add point assignment test

* Fix setting points y coordinate changes x instead (issue davisking#1794)

* Push all include and link options needed for dlib to pkg-config.  We do this by getting them from the same list cmake uses.

* Fixed incorrect return type

* Fixed grammar in comments

* Added missing include

* fixed typo in docs

* fix mismatch between documentation and implementation (davisking#1835)

* Fixed cmake warning

* fixing grammar

* Fix the CMake BUILDING_PYTHON_IN_MSVC variable not getting picked up where it should.

* pybind11: cmake: ignore the check between host-python and cross-compiler (davisking#1848)

When dlib is compiling, cmake will compare python architecture and target
architecture. So in cross-compiling case, it is irrevelant because host and
target architecture often differs. The main problem come from checking python
architecture on host and not on target.

Here is an error when compiling dlib from x86_64 to arm 32-bit target :
```
Python config failure: Python is 64-bit, chosen compiler is 32-bit
```

So :
- Skipping the comparation when cross-compiling is enabled.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Alexandre PAYEN <alexandre.payen@smile.fr>

* Const-correct a LAPACK declaration and add aarch64 as a 64-bit architecture (davisking#1859)

* Added aarch64 to list of 64-bit architechtures

* Const-corrected declaration of ssyevr

* Fix davisking#1849 by calling device_global_buffer() unconditionally (davisking#1862)

* Hold on to the CUDA buffer - second try
see: davisking#1855 (comment)

* Fix davisking#1849 by calling device_global_buffer() unconditionally

* Simplified the device_global_buffer() code and API.

* don't cast away constness (davisking#1865)

* dpoint mutates x-coord in y-property (see davisking#1794) (davisking#1866)

* add loss_mean_squared_per_channel (davisking#1863)

add loss_mean_squared_per_channel_and_pixel

* Clear truth_idxs between samples (davisking#1870)

* Clear truth_idxs between samples

* Move truth_idxs inside loop body after all

* Push to truth_idxs even when the box can't be detected; improve formatting

* Add an option to force static runtime (davisking#1847)

* dos2unix tell_visual_studio_to_use_static_runtime.cmake

* Add an option to force static runtime
nidegen pushed a commit to kapanu/dlib that referenced this pull request Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants