vfs: check userland buffers before reading them.
[haiku.git] / src / tools / restest / Warnings.cpp
blobd73740ca518dce52f91725821b2f7903c9a29597
1 // Warnings.h
3 #include "Warnings.h"
5 #include <stdio.h>
7 // constructor
8 Warnings::Warnings()
9 : fWarnings()
13 // destructor
14 Warnings::~Warnings()
16 for (int32 i = 0; BString* warning = (BString*)fWarnings.ItemAt(i); i++)
17 delete warning;
20 // GetCurrentWarnings
21 Warnings*
22 Warnings::GetCurrentWarnings()
24 return fCurrentWarnings;
27 // SetCurrentWarnings
28 void
29 Warnings::SetCurrentWarnings(Warnings* warnings)
31 fCurrentWarnings = warnings;
34 // AddWarning
35 void
36 Warnings::AddWarning(BString warning)
38 fWarnings.AddItem(new BString(warning));
41 // AddWarning
42 void
43 Warnings::AddWarning(const char* format,...)
45 va_list args;
46 va_start(args, format);
47 AddWarningV(format, args);
48 va_end(args);
51 // AddWarningV
52 void
53 Warnings::AddWarningV(const char* format, va_list arg)
55 char buffer[2048];
56 vsprintf(buffer, format, arg);
57 AddWarning(BString(buffer));
60 // AddCurrentWarning
61 void
62 Warnings::AddCurrentWarning(BString warning)
64 if (Warnings* currentWarnings = GetCurrentWarnings())
65 currentWarnings->AddWarning(warning);
68 // AddCurrentWarning
69 void
70 Warnings::AddCurrentWarning(const char* format,...)
72 va_list args;
73 va_start(args, format);
74 AddCurrentWarningV(format, args);
75 va_end(args);
78 // AddCurrentWarningV
79 void
80 Warnings::AddCurrentWarningV(const char* format, va_list arg)
82 char buffer[2048];
83 vsprintf(buffer, format, arg);
84 AddCurrentWarning(BString(buffer));
87 // CountWarnings
88 int32
89 Warnings::CountWarnings() const
91 return fWarnings.CountItems();
94 // WarningAt
95 const char*
96 Warnings::WarningAt(int32 index) const
98 const char* result = NULL;
99 if (BString* warning = (BString*)fWarnings.ItemAt(index))
100 result = warning->String();
101 return result;
104 // fCurrentWarnings
105 Warnings* Warnings::fCurrentWarnings = NULL;