Skip to content

Fixed gcc -Wstringop-overflow and -Wdeprecated-declarations. - #13

Open
AbdallaDalleh wants to merge 1 commit into
epics-modules:mainfrom
AbdallaDalleh:fix-gcc-warnings
Open

Fixed gcc -Wstringop-overflow and -Wdeprecated-declarations.#13
AbdallaDalleh wants to merge 1 commit into
epics-modules:mainfrom
AbdallaDalleh:fix-gcc-warnings

Conversation

@AbdallaDalleh

Copy link
Copy Markdown

1st warning:

../seq_mac.c: In function ‘seqMacEval’:
../seq_mac.c:81:5: warning: ‘strncpy’ specified bound depends on the length of the 
source argument [-Wstringop-overflow=]
     strncpy(outStr, value, valLth);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../seq_mac.c:75:14: note: length computed here
     valLth = strlen(value);

seqMacEval already passes the destination size as the 4th argument maxChar, this is clear in various calls:

  • src/seq/seq_main.c:395
  • src/seq/seq_if.c:668

2nd warning:

../../../include/seqMain.c: In function ‘main’:
../../../include/seqMain.c:28:9: warning: ‘epicsThreadExitMain’ is deprecated 
[-Wdeprecated-declarations]
         epicsThreadExitMain();

function call has been replaced with a loop+sleep, as the deprecation notice suggest. Similar case exist in test/validate/seqMain.c

1st warning:
../seq_mac.c: In function ‘seqMacEval’:
../seq_mac.c:81:5: warning: ‘strncpy’ specified bound depends on
the length of the source argument [-Wstringop-overflow=]
     strncpy(outStr, value, valLth);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../seq_mac.c:75:14: note: length computed here
     valLth = strlen(value);

seqMacEval already passes the destination size as the 4th argument
maxChar, this is clear in various calls:
  - src/seq/seq_main.c:395
  - src/seq/seq_if.c:668

2nd warning:
../../../include/seqMain.c: In function ‘main’:
../../../include/seqMain.c:28:9: warning: ‘epicsThreadExitMain’
is deprecated [-Wdeprecated-declarations]
         epicsThreadExitMain();

function call has been replaced with a loop+sleep, as the deprecation
notice suggest. Similar call exist in test/validate/seqMain.c
@ralphlange

Copy link
Copy Markdown
Member

Careful with the 2nd one:
This probably depends on the version of Base, and the sequencer needs to be working against a whole range...

@ralphlange

Copy link
Copy Markdown
Member

Works fine across Base versions, it seems.

@AbdallaDalleh

Copy link
Copy Markdown
Author

@ralphlange Do you have more details on why the MacOS test failed?

@ralphlange

Copy link
Copy Markdown
Member

Sorry, but no. I don't have access to a Mac and only know what's in the build log.

@mdavidsaver

Copy link
Copy Markdown
Contributor

... specified bound depends on the length of the source argument ...

This warning could probably be avoided by a switch to memcpy(). eg.

				valLth = strlen(value)+1; // note +1 to account for '\0'
				if (valLth > maxChar)
					valLth = maxChar;

				DEBUG("Value=%s, ", value);

				memcpy(outStr, value, valLth);
				outStr[valLth-1] = '\0'; // only needed when truncating, redundant otherwise
				maxChar -= valLth;
				outStr += valLth;

The current code does not appear to correctly handle truncation (which imo. should be an error).

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