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

Silence clang analyzer warnings #1521

Merged
merged 1 commit into from
Sep 20, 2024
Merged

Conversation

cgzones
Copy link
Member

@cgzones cgzones commented Aug 14, 2024

    linux/LinuxProcessTable.c:795:11: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      795 |    while (fgets(buffer, sizeof(buffer), fp)) {
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxProcessTable.c:795:11: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      795 |    while (fgets(buffer, sizeof(buffer), fp)) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxProcessTable.c:840:11: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      840 |    while (fgets(linebuf, sizeof(linebuf), file) != NULL) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxProcessTable.c:840:11: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      840 |    while (fgets(linebuf, sizeof(linebuf), file) != NULL) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    linux/LinuxMachine.c:81:22: warning: The 1st argument to 'openat' is between -99 and -1 but should be a valid file descriptor or AT_FDCWD [unix.StdCLibraryFunctions]
       81 |       int cpuDirFd = openat(dirfd(dir), entry->d_name, O_DIRECTORY | O_PATH | O_NOFOLLOW);
          |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxMachine.c:501:11: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      501 |    while (fgets(buffer, sizeof(buffer), file)) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxMachine.c:501:11: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      501 |    while (fgets(buffer, sizeof(buffer), file)) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    linux/Platform.c:467:22: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      467 |    } while ((bytes = fread(env + size, 1, capacity - size, fp)) > 0);
          |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:467:22: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      467 |    } while ((bytes = fread(env + size, 1, capacity - size, fp)) > 0);
          |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:585:15: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      585 |       total = fscanf(fp, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:585:15: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      585 |       total = fscanf(fp, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:789:21: warning: The 1st argument to 'openat' is between -99 and -1 but should be a valid file descriptor or AT_FDCWD [unix.StdCLibraryFunctions]
      789 |       int entryFd = openat(dirfd(dir), entryName, O_DIRECTORY | O_PATH);
          |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Split from #1513

    linux/LinuxProcessTable.c:795:11: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      795 |    while (fgets(buffer, sizeof(buffer), fp)) {
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxProcessTable.c:795:11: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      795 |    while (fgets(buffer, sizeof(buffer), fp)) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxProcessTable.c:840:11: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      840 |    while (fgets(linebuf, sizeof(linebuf), file) != NULL) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxProcessTable.c:840:11: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      840 |    while (fgets(linebuf, sizeof(linebuf), file) != NULL) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    linux/LinuxMachine.c:81:22: warning: The 1st argument to 'openat' is between -99 and -1 but should be a valid file descriptor or AT_FDCWD [unix.StdCLibraryFunctions]
       81 |       int cpuDirFd = openat(dirfd(dir), entry->d_name, O_DIRECTORY | O_PATH | O_NOFOLLOW);
          |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxMachine.c:501:11: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      501 |    while (fgets(buffer, sizeof(buffer), file)) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/LinuxMachine.c:501:11: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      501 |    while (fgets(buffer, sizeof(buffer), file)) {
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    linux/Platform.c:467:22: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      467 |    } while ((bytes = fread(env + size, 1, capacity - size, fp)) > 0);
          |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:467:22: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      467 |    } while ((bytes = fread(env + size, 1, capacity - size, fp)) > 0);
          |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:585:15: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
      585 |       total = fscanf(fp, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:585:15: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
      585 |       total = fscanf(fp, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    linux/Platform.c:789:21: warning: The 1st argument to 'openat' is between -99 and -1 but should be a valid file descriptor or AT_FDCWD [unix.StdCLibraryFunctions]
      789 |       int entryFd = openat(dirfd(dir), entryName, O_DIRECTORY | O_PATH);
          |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@BenBE BenBE added enhancement Extension or improvement to existing feature code quality ♻️ Code quality enhancement build system 🔧 Affects the build system rather then the user experience Linux 🐧 Linux related issues labels Sep 18, 2024
@BenBE BenBE modified the milestone: 3.4.0 Sep 18, 2024
@BenBE
Copy link
Member

BenBE commented Sep 20, 2024

This doesn't yet resolve all of the clang issues (tested with clang-20), but it's a good start. Let's do the remaining issues with #1513

@BenBE BenBE merged commit 49bb3c4 into htop-dev:main Sep 20, 2024
18 checks passed
@cgzones cgzones deleted the clang-analyzer branch September 22, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system 🔧 Affects the build system rather then the user experience code quality ♻️ Code quality enhancement enhancement Extension or improvement to existing feature Linux 🐧 Linux related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants