Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mojotx
Copy link
Contributor

@mojotx mojotx commented May 5, 2016

While compiling with clang on OS X, there are some warnings about undefined behavior because of embedded pre-processor directives in preprocessor macros.

Apparently sprintf(3) is implemented as a macro, and there are places where a directive is used to control parameters that are passed to sprintf. I did a quick test with some sample code, and it appears to work okay, but naturally it's not good to rely on undefined behavior.

I think the easiest fix would be to just modify the calls to sprintf() so that the directives wrap the complete macro calls, and not just wrap a parameter.

Also, I've submitted patches to the list before, but this is my first attempt at using a Github pull request instead of just writing a post directly to vim-dev. Hopefully this works! :-)

clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -Os -Wall -Wextra -fstack-protector -fstack-protector-all -pipe -std=c99 -pedantic -arch x86_64 -mtune=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       -o objects/fileio.o fileio.c
fileio.c:5234:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#ifdef LONG_LONG_OFF_T
 ^
fileio.c:5239:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#endif
 ^
fileio.c:5252:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#ifdef LONG_LONG_OFF_T
 ^
fileio.c:5257:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#endif
 ^
clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -Os -Wall -Wextra -fstack-protector -fstack-protector-all -pipe -std=c99 -pedantic -arch x86_64 -mtune=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       -o objects/tag.o tag.c
tag.c:2299:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#ifdef FEAT_MULTI_LANG
 ^
tag.c:2301:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#endif
 ^
clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -Os -Wall -Wextra -fstack-protector -fstack-protector-all -pipe -std=c99 -pedantic -arch x86_64 -mtune=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       -o objects/term.o term.c
term.c:2634:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#ifdef TERMINFO
 ^
term.c:2636:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
#else
 ^

@vim-ml
Copy link

vim-ml commented May 5, 2016

On Thursday, May 5, 2016 at 12:57:14 AM UTC-5, Michael Jarvis wrote:

Also, I've submitted patches to the list before, but this is my first attempt at using a Github pull request instead of just writing a post directly to vim-dev. Hopefully this works! :-)

It worked! 😃

@brammool brammool closed this in 827b165 May 5, 2016
@brammool
Copy link
Contributor

brammool commented May 5, 2016

Michael Jarvis wrote:

While compiling with clang on OS X, there are some warnings about
undefined behavior because of embedded pre-processor directives in
preprocessor macros.

Apparently sprintf(3) is implemented as a macro, and there are places
where a directive is used to control parameters that are passed to
sprintf. I did a quick test with some sample code, and it appears to
work okay, but naturally it's not good to rely on undefined behavior.

I think the easiest fix would be to just modify the calls to sprintf()
so that the directives wrap the complete macro calls, and not just
wrap a parameter.

Also, I've submitted patches to the list before, but this is my first
attempt at using a Github pull request instead of just writing a post
directly to vim-dev. Hopefully this works! :-)

Thanks. I'll adjust it a bit to avoid duplicating the expressions.

ERIC IDLE PLAYED: THE DEAD COLLECTOR, MR BINT (A VILLAGE NE'ER-DO -WELL VERY
KEEN ON BURNING WITCHES), SIR ROBIN, THE GUARD WHO DOESN'T
HICOUGH BUT TRIES TO GET THINGS STRAIGHT, CONCORDE (SIR
LAUNCELOT'S TRUSTY STEED), ROGER THE SHRUBBER (A SHRUBBER),
BROTHER MAYNARD
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \
\ an exciting new programming language -- http://www.Zimbu.org ///
\ help me help AIDS victims -- http://ICCF-Holland.org ///

micbou added a commit to micbou/vim that referenced this pull request May 11, 2016
- 7.4.1818: Help completion adds @en to all matches except the first
  one. Remove "break", go over all items.
- 7.4.1819: Compiler warnings when sprintf() is a macro. Don't interrupt
  sprintf() with an #ifdef. (Michael Jarvis, closes vim#788)
- 7.4.1820: Removing language from help tags too often. Only remove @en
  when not needed. (Hirohito Higashi)
- 7.4.1821: Test fails on MS-Windows. Sort the completion results.
- 7.4.1822: Redirecting stdout of a channel to "null" doesn't work.
  (Nicola) Correct the file descriptor number.
- 7.4.1823: Warning from 64 bit compiler. Add type cast. (Mike Williams)
- 7.4.1824: When a job is no longer referenced and does not have an exit
  callback the process may hang around in defunc state. (Nicola) Call
  job_status() if the job is running and won't get freed because it
  might still be useful.
- 7.4.1825: When job writes to buffer nothing is written. (Nicola) Do
  not discard a channel before writing is done.
- 7.4.1826: Callbacks are invoked when it's not safe. (Andrew Stewart)
  When a channel is to be closed don't invoke callbacks right away, wait
  for a safe moment.
- 7.4.1827: No error when invoking a callback when it's not safe. Add an
  error message. Avoid the error when freeing a channel.
- 7.4.1828: May try to access buffer that's already freed. When freeing
  a buffer remove it from any channel.
- 7.4.1829: No message on channel log when buffer was freed. Log a
  message.
- 7.4.1830: non-antialiased misnamed. Use NONANTIALIASED and
  NONANTIALIASED_QUALITY. (Kim Brouer, closes vim#793)
guns added a commit to guns/vim that referenced this pull request Nov 22, 2017
* origin/master: (25 commits)
  patch 7.4.1819 Problem:    Compiler warnings when sprintf() is a macro. Solution:   Don't interrupt sprintf() with an #ifdef. (Michael Jarvis,             closes vim#788)
  patch 7.4.1818 Problem:    Help completion adds @en to all matches except the first one. Solution:   Remove "break", go over all items.
  patch 7.4.1817 Problem:    The screen is not updated if a callback is invoked when closing a             channel. Solution:   Invoke redraw_after_callback().
  patch 7.4.1816 Problem:    Looping over a null list throws an error. Solution:   Skip over the for loop.
  patch 7.4.1815 Problem:    Compiler warnings for unused variables. (Ajit Thakkar) Solution:   Add a dummy initialization. (Yasuhiro Matsumoto)
  patch 7.4.1814 Problem:    A channel may be garbage collected while it's still being used by             a job. (James McCoy) Solution:   Mark the channel as used if the job is still used.  Do the same             for channels that are still used.
  patch 7.4.1813 Problem:    Memory access error when running test_quickfix. Solution:   Allocate one more byte. (Yegappan Lakshmanan)
  patch 7.4.1812 Problem:    Failure on startup with Athena and Motif. Solution:   Check for INVALCOLOR. (Kazunobu Kuriyama)
  patch 7.4.1811 Problem:    Netbeans channel gets garbage collected. Solution:   Set reference in nb_channel.
  patch 7.4.1810 Problem:    Sending DETACH after a channel was closed isn't useful. Solution:   Only add DETACH for a netbeans channel.
  patch 7.4.1809 Problem:    Using wrong short option name for 'termguicolors'. Solution:   Use the option name.
  patch 7.4.1808 Problem:    Using wrong feature name to check for 'termguicolors'. Solution:   Use the right feature name. (Ken Takata)
  patch 7.4.1807 Problem:    Test_out_close_cb sometimes fails. Solution:   Always write DETACH to out, not err.
  patch 7.4.1806 Problem:    'termguicolors' option missing from the options window. Solution:   Add the entry.
  Update runtime files.
  patch 7.4.1805 Problem:    Running tests in shadow dir fails. Solution:   Link the samples directory
  patch 7.4.1804 Problem:    Can't use Vim as MANPAGER. Solution:   Add manpager.vim. (Enno Nagel, closes vim#491)
  patch 7.4.1803 Problem:    GTK3 doesn't handle menu separaters properly. Solution:   Use gtk_separator_menu_item_new(). (Kazunobu Kuriyama)
  patch 7.4.1802 Problem:    Quickfix doesn't handle long lines well, they are split. Solution:   Drop characters after a limit. (Anton Lindqvist)
  patch 7.4.1801 Problem:    Make uninstall leaves file behind. Solution:   Delete rgb.txt. (Kazunobu Kuriyama)
  ...
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