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

CI: Add github code quality analysis (codeql) #584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thesamesam
Copy link
Contributor

No description provided.

@N-R-K
Copy link
Contributor

N-R-K commented Jan 28, 2023

The following patch should solve one of the issues reported in the codeql scan. It also removes usage of utime which seems to be deprecated by POSIX 1

diff --git a/src/swclock/swclock.c b/src/swclock/swclock.c
index e526bd38..83b15c95 100644
--- a/src/swclock/swclock.c
+++ b/src/swclock/swclock.c
@@ -78,14 +78,12 @@ int main(int argc, char **argv)
 		eerrorx("swclock: Reference file was not specified");
 
 	if (sflag) {
-		if (stat(file, &sb) == -1) {
-			opt = open(file, O_WRONLY | O_CREAT, 0644);
-			if (opt == -1)
-				eerrorx("swclock: open: %s", strerror(errno));
-			close(opt);
-		} else
-			if (utime(file, NULL) == -1)
-				eerrorx("swclock: utime: %s", strerror(errno));
+		int fd = open(file, O_WRONLY | O_CREAT, 0644);
+		if (fd == -1)
+			eerrorx("swclock: open: %s", strerror(errno));
+		if (futimens(fd, NULL) == -1)
+			eerrorx("swclock: futimens: %s", strerror(errno));
+		close(fd);
 		return 0;
 	}
 

Footnotes

  1. https://www.man7.org/linux/man-pages/man3/utime.3p.html#FUTURE_DIRECTIONS

@vapier
Copy link
Member

vapier commented Jan 28, 2023

can you send a PR ? we're not going to copy & paste patches from comments ...

@N-R-K
Copy link
Contributor

N-R-K commented Jan 28, 2023

can you send a PR ? we're not going to copy & paste patches from comments ...

Sure. I was thinking @thesamesam might have wanted to add that to this PR since it's somewhat related.

EDIT: done at #591

@thesamesam thesamesam force-pushed the codeql branch 4 times, most recently from d86cdcb to 6ccc8a2 Compare March 26, 2025 12:58
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.

3 participants