Skip to content

Commit

Permalink
lib: add PoolMem(const std::string&) constructor
Browse files Browse the repository at this point in the history
You can now construct a PoolMem from a std::string if needed. We also
mark the single-argument constructors explicit, so you can't
accidentially convert an integer oder char* into a PoolMem.
  • Loading branch information
arogge authored and pstorz committed Mar 9, 2022
1 parent e2459fc commit 408e31a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion core/src/lib/mem_pool.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -42,6 +42,9 @@
*
* Kern E. Sibbald
*/
#if defined(HAVE_WIN32)
# include "compat.h"
#endif
#include "lib/mem_pool.h"

#include <stdarg.h>
Expand Down
8 changes: 5 additions & 3 deletions core/src/lib/mem_pool.h
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2016-2021 Bareos GmbH & Co. KG
Copyright (C) 2016-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -30,6 +30,7 @@

#include <stdarg.h>
#include <string.h>
#include <string>
#include "include/bc_types.h"

POOLMEM* GetPoolMemory(int pool) noexcept;
Expand Down Expand Up @@ -71,17 +72,18 @@ class PoolMem {
mem = GetPoolMemory(PM_NAME);
*mem = 0;
}
PoolMem(int pool)
explicit PoolMem(int pool)
{
mem = GetPoolMemory(pool);
*mem = 0;
}
PoolMem(const char* str)
explicit PoolMem(const char* str)
{
mem = GetPoolMemory(PM_NAME);
*mem = 0;
strcpy(str);
}
explicit PoolMem(const std::string& str) : PoolMem(str.c_str()) {}
~PoolMem()
{
FreePoolMemory(mem);
Expand Down

0 comments on commit 408e31a

Please sign in to comment.