libprint: Fix using auto_ptr to array.

Change-Id: If22530aba951e2856fc03cf59de167353db42604
Reviewed-on: https://review.haiku-os.org/727
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Murai Takashi 2018-11-23 06:11:56 +09:00 committed by Jérôme Duval
parent 2c5c300420
commit 6d2736585e

View File

@ -7,13 +7,14 @@
#include "PrinterDriver.h"
#include <fs_attr.h> // for attr_info
#include <DataIO.h>
#include <File.h>
#include <FindDirectory.h>
#include <Message.h>
#include <Node.h>
#include <Path.h>
#include <StackOrHeapArray.h>
#include <String.h>
#include <memory> // for auto_ptr
#include "AboutBox.h"
#include "AddPrinterDlg.h"
@ -175,14 +176,14 @@ bool
PrinterDriver::_ReadSettings(const char* attrName, BMessage* settings)
{
attr_info info;
char* data;
ssize_t size;
settings->MakeEmpty();
if (fSpoolFolder->GetAttrInfo(attrName, &info) == B_OK && info.size > 0) {
data = new char[info.size];
auto_ptr<char> _data(data);
BStackOrHeapArray<char, 0> data(info.size);
if (!data.IsValid())
return false;
size = fSpoolFolder->ReadAttr(attrName, B_MESSAGE_TYPE, 0, data, info.size);
if (size == info.size && settings->Unflatten(data) == B_OK) {
return true;
@ -197,15 +198,13 @@ PrinterDriver::_WriteSettings(const char* attrName, BMessage* settings)
{
if (settings == NULL || settings->what != 'okok') return;
size_t size;
char* data;
status_t status;
BMallocIO data;
status = settings->Flatten(&data);
size = settings->FlattenedSize();
data = new char[size];
auto_ptr<char> _data(data);
if (data != NULL && settings->Flatten(data, size) == B_OK) {
fSpoolFolder->WriteAttr(attrName, B_MESSAGE_TYPE, 0, data, size);
if (status == B_OK) {
fSpoolFolder->WriteAttr(attrName, B_MESSAGE_TYPE, 0, data.Buffer(),
data.BufferLength());
}
}