octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #55046] Crash with trivial script on dev


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #55046] Crash with trivial script on dev
Date: Wed, 21 Nov 2018 03:08:43 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36

Follow-up Comment #9, bug #55046 (project octave):

Rik, great observation with that warning!  Your patch (file #45493) solves my
issue, I can fully cope with a warning in this case and consider this item to
be fixed.

I checked my build logs and did not find anything like


warning: format ‘%s’ expects type ‘char *’,


which is usually shown when compiling with "-Wformat".

That might be because the compiler has no information that calls to


extern OCTINTERP_API void warning (const char *fmt, ...);


from <octave/error.h> are eventually passed to "printf"-like functions.

To make Octave more robust against such things, I propose a simple solution
for GCC:


#include <octave/oct.h>
#include <octave/error.h>

// Inspired by
https://stackoverflow.com/questions/2223968/how-to-get-warnings-of-incorrect-string-formatting-c
void save_warning (const char *fmt, ...)
#if defined(__GNUC__) || defined(__GNUG__)
  __attribute__ ((__format__(printf, 1, 2)));
#endif

int main () {
  warning ("load-path: update failed for '%s', removing from path", 1.3);
  warning ("load-path: update failed for '%s', removing from path");
  save_warning ("load-path: update failed for '%s', removing from path",
1.3);
  save_warning ("load-path: update failed for '%s', removing from path");
  return 0;
}

void save_warning (const char *fmt, ...)
{
  va_list args;
  va_start (args, fmt);
  warning (fmt, args);
  va_end (args);
}



Compile with


mkoctfile -Wformat -o main.exe main.cc


This means, that we only have to extend the definition of "warning" and
"error" in "error.h" by a small GCC macro and we can get static compile time
checking for free! =)

Any thoughts?

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?55046>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]