Fix crash in SpeechRecognizerImpl introduced in AudioParams refactor.
[chromium-blink-merge.git] / gpu / command_buffer / common / mailbox.cc
blob21602ab6d4df291b19348f365d9d266abce12663
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/common/mailbox.h"
7 #include <string.h>
9 #include "base/logging.h"
10 #include "base/rand_util.h"
12 namespace gpu {
14 Mailbox::Mailbox() {
15 memset(name, 0, sizeof(name));
18 bool Mailbox::IsZero() const {
19 for (size_t i = 0; i < arraysize(name); ++i) {
20 if (name[i])
21 return false;
23 return true;
26 void Mailbox::SetZero() {
27 memset(name, 0, sizeof(name));
30 void Mailbox::SetName(const int8* n) {
31 DCHECK(IsZero() || !memcmp(name, n, sizeof(name)));
32 memcpy(name, n, sizeof(name));
35 Mailbox Mailbox::Generate() {
36 Mailbox result;
37 // Generates cryptographically-secure bytes.
38 base::RandBytes(result.name, sizeof(result.name));
39 #if !defined(NDEBUG)
40 int8 value = 1;
41 for (size_t i = 1; i < sizeof(result.name); ++i)
42 value ^= result.name[i];
43 result.name[0] = value;
44 #endif
45 return result;
48 bool Mailbox::Verify() const {
49 #if !defined(NDEBUG)
50 int8 value = 1;
51 for (size_t i = 0; i < sizeof(name); ++i)
52 value ^= name[i];
53 return value == 0;
54 #else
55 return true;
56 #endif
59 } // namespace gpu