Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obs-nvenc: Fix reading uninitialized variable #11263

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

norihiro
Copy link
Contributor

@norihiro norihiro commented Sep 11, 2024

Description

Define success = false at the beginning of the function static bool nvenc_check().

Motivation and Context

I found a warning below as commented in the PR 11153.

[ 46%] Building C object plugins/obs-nvenc/CMakeFiles/obs-nvenc.dir/nvenc-helpers.c.o
obs-studio/plugins/obs-nvenc/nvenc-helpers.c: In function ‘nvenc_check’:
obs-studio/plugins/obs-nvenc/nvenc-helpers.c:385:16: warning: ‘success’ may be used uninitialized [-Wmaybe-uninitialized]
  385 |         return success;
      |                ^~~~~~~
obs-studio/plugins/obs-nvenc/nvenc-helpers.c:347:14: note: ‘success’ was declared here
  347 |         bool success = config_get_bool(config, "general", "nvenc_supported");
      |              ^~~~~~~

How Has This Been Tested?

OS: Fedora 39 (GCC 13.3.1)

I ran these commands to hit the error.

ln -s libobs.so.30 lib64/libnvidia-encode.so.1
rm bin/obs-nvenc-test
ln -s /usr/bin/true bin/obs-nvenc-test

Then checked log file.

Log from master branch:

---------------------------------                                                                                                               
Loading module: obs-nvenc.so                                                                                                                    
[NVENC] Seems the NVENC test subprocess crashed. Better there than here I guess.                                                                
---------------------------------                                                                                                               

Log from this branch:

---------------------------------                                                                                                               
Loading module: obs-nvenc.so                                                                                                                    
[NVENC] Seems the NVENC test subprocess crashed. Better there than here I guess.                                                                
NVENC not supported                                                                                                                             
Failed to initialize module 'obs-nvenc.so'                                                                                                      
---------------------------------                                                                                                               

It shows Failed to initialize module 'obs-nvenc.so' so that I confirmed the function returns false.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Copy link
Member

@derrod derrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that MSVC and CI didn't catch this but lgtm

@norihiro
Copy link
Contributor Author

norihiro commented Sep 11, 2024

Weird that MSVC and CI didn't catch this but lgtm

CI also shows the warning.

  /home/runner/work/obs-studio/obs-studio/plugins/obs-nvenc/nvenc-helpers.c:385:16: warning: ‘success’ may be used uninitialized [-Wmaybe-uninitialized]
    385 |         return success;
        |                ^~~~~~~
  /home/runner/work/obs-studio/obs-studio/plugins/obs-nvenc/nvenc-helpers.c:347:14: note: ‘success’ was declared here
    347 |         bool success = config_get_bool(config, "general", "nvenc_supported");
        |              ^~~~~~~

Though, we have -Wno-error=maybe-uninitialized so that CI didn't fail. We can probably raise this warning to error for GCC >= 13.0, except librtmp.

# * Disable false-positive warning in GCC 12.1.0 and later
# * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1.0)
add_compile_options(-Wno-error=maybe-uninitialized)
endif()

Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RytoEX RytoEX added this to the OBS Studio 31 milestone Sep 11, 2024
@RytoEX RytoEX added the Bug Fix Non-breaking change which fixes an issue label Sep 11, 2024
@RytoEX RytoEX merged commit e87593b into obsproject:master Sep 11, 2024
14 checks passed
@norihiro norihiro deleted the fix-nvenc-uninitialized branch September 12, 2024 00:53
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants