Bug Summary

File:/boot/home/haiku/haiku/src/add-ons/kernel/file_systems/btrfs/Chunk.cpp
Location:line 35, column 2
Description:Null pointer argument in call to memory copy function

Annotated Source Code

1/*
2 * Copyright 2011, Haiku Inc. All rights reserved.
3 * This file may be used under the terms of the MIT License.
4 *
5 * Authors:
6 * Jérôme Duval
7 */
8
9
10#include "Chunk.h"
11
12#include <stdlib.h>
13#include <string.h>
14
15
16//#define TRACE_BTRFS
17#ifdef TRACE_BTRFS
18# define TRACE(x...); dprintf("\33[34mbtrfs:\33[0m " x)
19#else
20# define TRACE(x...); ;
21#endif
22# define FATAL(x...)dprintf("\33[34mbtrfs:\33[0m " x...) dprintf("\33[34mbtrfs:\33[0m " x)
23
24
25Chunk::Chunk(struct btrfs_chunk* chunk, fsblock_t offset)
26 :
27 fChunk(NULL__null),
28 fInitStatus(B_OK((int)0))
29{
30 fChunkOffset = offset;
31 fChunk = (struct btrfs_chunk*)malloc(sizeof(struct btrfs_chunk)
1
Value assigned to field 'fChunk'
32 + chunk->StripeCount() * sizeof(struct btrfs_stripe));
33 if (fChunk == NULL__null)
2
Assuming pointer value is null
3
Taking true branch
34 fInitStatus = B_NO_MEMORY((-2147483647 - 1) + 0);
35 memcpy(fChunk, chunk, sizeof(struct btrfs_chunk)
4
Null pointer argument in call to memory copy function
36 + chunk->StripeCount() * sizeof(struct btrfs_stripe));
37
38 TRACE("chunk[0] length %" B_PRIu64 " owner %" B_PRIu64 " stripe_length %";
39 B_PRIu64 " type %" B_PRIu64 " stripe_count %u sub_stripes %u ";
40 "sector_size %" B_PRIu32 "\n", chunk->Length(), chunk->Owner(),;
41 chunk->StripeLength(), chunk->Type(), chunk->StripeCount(),;
42 chunk->SubStripes(), chunk->SectorSize());;
43 for(int32 i = 0; i < chunk->StripeCount(); i++) {
44 TRACE("chunk.stripe[%" B_PRId32 "].physical %" B_PRId64 " deviceid %";
45 B_PRId64 "\n", i, chunk->stripes[i].Offset(),;
46 chunk->stripes[i].DeviceID());;
47 }
48}
49
50
51Chunk::~Chunk()
52{
53 free(fChunk);
54}
55
56
57uint32
58Chunk::Size() const
59{
60 return sizeof(struct btrfs_chunk)
61 + fChunk->StripeCount() * sizeof(struct btrfs_stripe);
62}
63
64
65status_t
66Chunk::FindBlock(off_t logical, off_t &physical)
67{
68 if (fChunk == NULL__null)
69 return B_NO_INIT((-2147483647 - 1) + 13);
70
71 if (logical < (off_t)fChunkOffset
72 || logical > (off_t)(fChunkOffset + fChunk->Length()))
73 return B_BAD_VALUE((-2147483647 - 1) + 5);
74
75 // only one stripe
76 physical = logical + fChunk->stripes[0].Offset() - fChunkOffset;
77 return B_OK((int)0);
78}
79