Skip to content

Fix various warnings on MacOS / Unix systems - #22

Open
reinauer wants to merge 8 commits into
simh:masterfrom
reinauer:warnings
Open

Fix various warnings on MacOS / Unix systems#22
reinauer wants to merge 8 commits into
simh:masterfrom
reinauer:warnings

Conversation

@reinauer

Copy link
Copy Markdown
  • Fix "assignment as a condition" warnings
  • Switch function declarations from K&R to ANSI C
  • Fix warnings for unused function parameters
  • Remove unused variables
  • Type and format fixes
  • config11: Use fgets instead of gets
  • hpconvert: Use mkstemp() instead of tmpnam()
  • ods2: Use proper braces in direct.c

A lot of code assigns variables within an if condition, like:
if (ppos = strrchr (oname, '.')) strcpy (ppos, ".new");
This results in warnings with modern compilers:
warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
Fix the code by properly adding parenthesis around these assignments.
From the gets() man page:
The gets() function cannot be used securely. Because of its lack
of bounds checking, and the inability for the calling program to
reliably determine the length of the next incoming line, the use of
this function enables malicious users to arbitrarily change a running
program's functionality through a buffer overflow attack. It is
strongly suggested that the fgets() function be used in all cases.
From the tmpnam() man page:
The tmpnam() and tempnam() functions are susceptible to a race
condition occurring between the selection of the file name and
the creation of the file, which allows malicious users to potentially
overwrite arbitrary files in the system, depending on the level of
privilege of the running program.
Sign up for freeto 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.

1 participant

@reinauer