136ac495dSmrg /* Checking vsprintf.
2*8feb0f0bSmrg Copyright (C) 2005-2020 Free Software Foundation, Inc.
336ac495dSmrg
436ac495dSmrg This file is part of GCC.
536ac495dSmrg
636ac495dSmrg GCC is free software; you can redistribute it and/or modify it under
736ac495dSmrg the terms of the GNU General Public License as published by the Free
836ac495dSmrg Software Foundation; either version 3, or (at your option) any later
936ac495dSmrg version.
1036ac495dSmrg
1136ac495dSmrg In addition to the permissions in the GNU General Public License, the
1236ac495dSmrg Free Software Foundation gives you unlimited permission to link the
1336ac495dSmrg compiled version of this file into combinations with other programs,
1436ac495dSmrg and to distribute those combinations without any restriction coming
1536ac495dSmrg from the use of this file. (The General Public License restrictions
1636ac495dSmrg do apply in other respects; for example, they cover modification of
1736ac495dSmrg the file, and distribution when not linked into a combine
1836ac495dSmrg executable.)
1936ac495dSmrg
2036ac495dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
2136ac495dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
2236ac495dSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2336ac495dSmrg for more details.
2436ac495dSmrg
2536ac495dSmrg Under Section 7 of GPL version 3, you are granted additional
2636ac495dSmrg permissions described in the GCC Runtime Library Exception, version
2736ac495dSmrg 3.1, as published by the Free Software Foundation.
2836ac495dSmrg
2936ac495dSmrg You should have received a copy of the GNU General Public License and
3036ac495dSmrg a copy of the GCC Runtime Library Exception along with this program;
3136ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
3236ac495dSmrg <http://www.gnu.org/licenses/>. */
3336ac495dSmrg
3436ac495dSmrg #include "config.h"
3536ac495dSmrg #include <ssp/ssp.h>
3636ac495dSmrg #include <stdarg.h>
3736ac495dSmrg #ifdef HAVE_LIMITS_H
3836ac495dSmrg # include <limits.h>
3936ac495dSmrg #endif
4036ac495dSmrg #ifdef HAVE_STDIO_H
4136ac495dSmrg # include <stdio.h>
4236ac495dSmrg #endif
4336ac495dSmrg
4436ac495dSmrg extern void __chk_fail (void) __attribute__((__noreturn__));
4536ac495dSmrg
4636ac495dSmrg #ifdef HAVE_USABLE_VSNPRINTF
4736ac495dSmrg int
__vsprintf_chk(char * s,int flags,size_t slen,const char * format,va_list arg)4836ac495dSmrg __vsprintf_chk (char *s, int flags __attribute__((unused)),
4936ac495dSmrg size_t slen, const char *format, va_list arg)
5036ac495dSmrg {
5136ac495dSmrg int done;
5236ac495dSmrg
5336ac495dSmrg if (slen > (size_t) INT_MAX)
5436ac495dSmrg done = vsprintf (s, format, arg);
5536ac495dSmrg else
5636ac495dSmrg {
5736ac495dSmrg done = vsnprintf (s, slen, format, arg);
5836ac495dSmrg if (done >= 0 && (size_t) done >= slen)
5936ac495dSmrg __chk_fail ();
6036ac495dSmrg }
6136ac495dSmrg return done;
6236ac495dSmrg }
6336ac495dSmrg #endif
64