ust_safe_snprintf: add openbsd mbrtowc() function
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 1 Mar 2010 22:11:45 +0000 (17:11 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 1 Mar 2010 22:11:45 +0000 (17:11 -0500)
The glibc one calls malloc, which we are trying to avoid.

libust/buffers.h
snprintf/Makefile.am
snprintf/mbrtowc_sb.c [new file with mode: 0644]
snprintf/various.h
snprintf/vfprintf.c

index db4b7089071e42358d18b4172da60ca2a6963ff6..a2f17a9f78d01e83f3e1ee2a5d4e7eb40e92f081 100644 (file)
@@ -357,6 +357,7 @@ static __inline__ int ltt_reserve_slot(struct ust_trace *trace,
         */
        /* FIXME: make this rellay per cpu? */
        if (unlikely(LOAD_SHARED(ltt_nesting) > 4)) {
+               DBG("Dropping event because nesting is too deep.");
                local_inc(&buf->events_lost);
                return -EPERM;
        }
index 1bd33fa429efb6ef9c139a91ff3ec15e8e51a031..04148b71aeece6b46b0d1a4312d86ee894567710 100644 (file)
@@ -8,6 +8,7 @@ libustsnprintf_la_SOURCES = \
        fvwrite.c \
        fvwrite.h \
        local.h \
+       mbrtowc_sb.c \
        snprintf.c \
        various.h \
        vfprintf.c \
diff --git a/snprintf/mbrtowc_sb.c b/snprintf/mbrtowc_sb.c
new file mode 100644 (file)
index 0000000..0abecc8
--- /dev/null
@@ -0,0 +1,53 @@
+/*     $OpenBSD: mbrtowc_sb.c,v 1.4 2005/11/27 20:03:06 cloder Exp $   */
+/*     $NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $     */
+
+/*
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+/*ARGSUSED*/
+size_t
+ust_safe_mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+
+       /* pwc may be NULL */
+       /* s may be NULL */
+       /* ps appears to be unused */
+
+       if (s == NULL)
+               return 0;
+       if (n == 0)
+               return (size_t)-1;
+       if (pwc)
+               *pwc = (wchar_t)(unsigned char)*s;
+       return (*s != '\0');
+}
index dab78edabefe7a4f869dcc37372b02eb90894a22..2a18461b24bf80423640f40e320ef83704a2e734 100644 (file)
@@ -88,4 +88,6 @@ typedef struct __sFILE {
 extern int ust_safe_fflush(LFILE *fp);
 extern int ust_safe_vfprintf(LFILE *fp, const char *fmt0, va_list ap);
 
+extern size_t ust_safe_mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
+
 #endif /* UST_SNPRINTF_VARIOUS_H */
index 4fc86bf08d8ded480ae73558f77e8fe8e2792a51..d4953be28dca8f60024efabacda83e14cba4c157 100644 (file)
@@ -399,7 +399,7 @@ int ust_safe_vfprintf(LFILE *fp, const char *fmt0, va_list ap)
         */
        for (;;) {
                cp = fmt;
-               while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
+               while ((n = ust_safe_mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
                        fmt += n;
                        if (wc == '%') {
                                fmt--;
@@ -1071,7 +1071,7 @@ __find_arguments(const char *fmt0, va_list ap, union arg **argtable,
         */
        for (;;) {
                cp = fmt;
-               while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
+               while ((n = ust_safe_mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
                        fmt += n;
                        if (wc == '%') {
                                fmt--;
This page took 0.02553 seconds and 4 git commands to generate.