third_party/modest/source/myfont/name.c

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 65 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« third_party/modest/source/myfont/myosi.c ↑ Summary third_party/modest/source/myfont/os_2.c »
1 /*
2 Copyright (C) 2016-2017 Alexander Borisov
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18 Author: lex.borisov@gmail.com (Alexander Borisov)
19 */
20  
21 #include "myfont/name.h"
22  
23 0 mystatus_t myfont_load_table_name(myfont_font_t *mf, uint8_t* font_data, size_t data_size)
24 {
25 0 memset(&mf->table_name, 0, sizeof(myfont_table_name_t));
26
27 0 ▶ if(mf->cache.tables_offset[MyFONT_TKEY_name] == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(mf->cache.tables_offset[MyFONT_TKEY_name] == 0) 0 0 0
28 0 return MyFONT_STATUS_OK;
29
30 0 myfont_table_name_t *tname = &mf->table_name;
31 0 const uint32_t table_offset = mf->cache.tables_offset[MyFONT_TKEY_name];
32 0 uint32_t pos = table_offset + 6;
33
34 0 ▶ if(pos > data_size)
Branch: 1 branch
BranchTrueFalseTotal
if(pos > data_size) 0 0 0
35 0 return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
36
37 /* get current data */
38 0 uint8_t *data = &font_data[table_offset];
39
40 0 tname->format = myfont_read_u16(&data);
41 0 tname->count = myfont_read_u16(&data);
42 0 tname->stringOffset = myfont_read_u16(&data);
43
44 0 pos = pos + (tname->count * 12);
45 0 ▶ if(pos > data_size) {
Branch: 1 branch
BranchTrueFalseTotal
if(pos > data_size) { 0 0 0
46 0 tname->count = 0;
47 0 return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
48 }
49
50 0 myfont_record_t *record = (myfont_record_t *)myfont_calloc(mf, tname->count, sizeof(myfont_record_t));
51
52 0 ▶ if(record == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(record == NULL) 0 0 0
53 0 return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
54
55 0 ▶ for(uint16_t i = 0; i < tname->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(uint16_t i = 0; i < tname->count; i++) { 0 0 0
56 0 record[i].platformID = myfont_read_u16(&data);
57 0 record[i].encodingID = myfont_read_u16(&data);
58 0 record[i].languageID =myfont_read_u16(&data);
59 0 record[i].nameID = myfont_read_u16(&data);
60 0 record[i].length = myfont_read_u16(&data);
61 0 record[i].offset = myfont_read_u16(&data);
62 }
63
64 0 tname->nameRecord = record;
65
66 0 ▶ if(tname->format == 1)
Branch: 1 branch
BranchTrueFalseTotal
if(tname->format == 1) 0 0 0
67 {
68 0 pos += 2;
69 0 ▶ if(pos > data_size)
Branch: 1 branch
BranchTrueFalseTotal
if(pos > data_size) 0 0 0
70 0 return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
71
72 0 tname->langTagCount = myfont_read_u16(&data);
73
74 0 pos = pos + (tname->langTagCount * 4);
75 0 ▶ if(pos > data_size) {
Branch: 1 branch
BranchTrueFalseTotal
if(pos > data_size) { 0 0 0
76 0 tname->langTagCount = 0;
77 0 return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
78 }
79
80 0 myfont_ltag_record_t *lang_record = (myfont_ltag_record_t *)myfont_calloc(mf, tname->langTagCount, sizeof(myfont_ltag_record_t));
81
82 0 ▶ if(lang_record == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(lang_record == NULL) 0 0 0
83 0 return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
84
85 0 ▶ for(uint16_t i = 0; i < tname->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(uint16_t i = 0; i < tname->count; i++) { 0 0 0
86 0 lang_record[i].length = myfont_read_u16(&data);
87 0 lang_record[i].offset = myfont_read_u16(&data);
88 }
89
90 0 tname->langTagRecord = lang_record;
91 }
92
93 0 return MyFONT_STATUS_OK;
94 }
95  
« third_party/modest/source/myfont/myosi.c ↑ Summary third_party/modest/source/myfont/os_2.c »