From 65c0cb48fc75155ca7851c3ad97d397054766bf5 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 24 Apr 2015 08:43:22 +0200 Subject: [PATCH] tmpfile: fix out-of-memory check another catch by cppcheck * src/misc/tmpfile.cc: Here. --- src/misc/tmpfile.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/misc/tmpfile.cc b/src/misc/tmpfile.cc index c0d5a9f87..d0f99c2b8 100644 --- a/src/misc/tmpfile.cc +++ b/src/misc/tmpfile.cc @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013 Laboratoire de Recherche et Développement +// Copyright (C) 2013, 2015 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -52,10 +52,9 @@ namespace spot size_t slen = 0; if (suffix) len += slen = strlen(suffix); - *name = static_cast(malloc(tmpdirlen + 1 + len + 6 + 1)); - if (!name) + char* x = *name = static_cast(malloc(tmpdirlen + 1 + len + 6 + 1)); + if (!x) throw std::bad_alloc(); - char* x = *name; if (tmpdir) { x = stpcpy(x, tmpdir); @@ -147,4 +146,3 @@ namespace spot delete to_clean.front(); } } -