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

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

[Octave-bug-tracker] [bug #60016] libqhull was deprecated in favor of li


From: Rik
Subject: [Octave-bug-tracker] [bug #60016] libqhull was deprecated in favor of libqhull_r
Date: Thu, 8 Apr 2021 23:41:57 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36

Follow-up Comment #13, bug #60016 (project octave):

Besides refreshing the patch as mentioned in comment #12, I don't think the
switch from OCTAVE_LOCAL_BUFFER to std::string is correct.


-      // Qhull flags argument is not const char*
-      OCTAVE_LOCAL_BUFFER (char, flags, 9 + options.length ());
-
-      sprintf (flags, "qhull d %s", options.c_str ());
+      std::string cmd = "qhull d " + options;
 
       octave::unwind_protect frame;
 
@@ -181,16 +178,19 @@ Undocumented internal function.
 
       frame.add_fcn (close_fcn, outfile);
 
-      int exitcode = qh_new_qhull (dim, n, pt_array,
-                                   ismalloc, flags, outfile, errfile);
+      qhT context;
+      qhT* qh = &context;
+
+      int exitcode = qh_new_qhull (qh, dim, n, pt_array,
+                                   ismalloc, &cmd[0], outfile, errfile);



The function qh_new_qhull is expecting a non-const C string which is thus of
type


char *


If you want a C-delimited string (i.e., it ends with \0) then you need to use
the c_str() function.  But that library function returns a const pointer to
char.

The way you coded it you use the [] operator access which returns a reference
to char and then you take the address of that reference to get a pointer to
char.


&cmd[0]


But, there is no guarantee of any kind that the C++ standard library has
organized the string internally to have a trailing null character (\0).  The
C++ standard maintains the length separately from the storage so it may be
that there are trailing null bytes, but I'm pretty sure it's not guaranteed.

Hence, the strategy that Octave used to create a block of memory of the
correct size, put the C string in that memory block, and then use a pointer to
that block in the call to qh_new_qhull.

If we're certain that qh_new_qhull will not change the string in any way then
we could use the std::string c_str() function to get a properly formed
C-language string and then throw away the 'const' attribute with a const_cast.
 But we do need to be certain the memory won't be changed.

    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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