PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/gfx/ots/src/ots.cc

https://bitbucket.org/MeeGoAdmin/mozilla-central/
C++ | 630 lines | 479 code | 92 blank | 59 comment | 120 complexity | b164c83ede21de31e095e0b38c6e8e2b MD5 | raw file
Possible License(s): AGPL-1.0, MIT, BSD-3-Clause, Apache-2.0, LGPL-2.1, 0BSD, LGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0, JSON
  1. // Copyright (c) 2009 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.
  4. #include "ots.h"
  5. #include <sys/types.h>
  6. #include <zlib.h>
  7. #include <algorithm>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <map>
  11. #include <vector>
  12. // The OpenType Font File
  13. // http://www.microsoft.com/typography/otspec/cmap.htm
  14. namespace {
  15. bool g_debug_output = true;
  16. struct OpenTypeTable {
  17. uint32_t tag;
  18. uint32_t chksum;
  19. uint32_t offset;
  20. uint32_t length;
  21. uint32_t uncompressed_length;
  22. };
  23. // Round a value up to the nearest multiple of 4. Note that this can overflow
  24. // and return zero.
  25. template<typename T> T Round4(T value) {
  26. return (value + 3) & ~3;
  27. }
  28. uint32_t Tag(const char *tag_str) {
  29. uint32_t ret;
  30. std::memcpy(&ret, tag_str, 4);
  31. return ret;
  32. }
  33. bool CheckTag(uint32_t tag_value) {
  34. for (unsigned i = 0; i < 4; ++i) {
  35. const uint32_t check = tag_value & 0xff;
  36. if (check < 32 || check > 126) {
  37. return false; // non-ASCII character found.
  38. }
  39. tag_value >>= 8;
  40. }
  41. return true;
  42. }
  43. struct OutputTable {
  44. uint32_t tag;
  45. size_t offset;
  46. size_t length;
  47. uint32_t chksum;
  48. static bool SortByTag(const OutputTable& a, const OutputTable& b) {
  49. const uint32_t atag = ntohl(a.tag);
  50. const uint32_t btag = ntohl(b.tag);
  51. return atag < btag;
  52. }
  53. };
  54. struct Arena {
  55. public:
  56. ~Arena() {
  57. for (std::vector<uint8_t*>::iterator
  58. i = hunks_.begin(); i != hunks_.end(); ++i) {
  59. delete[] *i;
  60. }
  61. }
  62. uint8_t* Allocate(size_t length) {
  63. uint8_t* p = new uint8_t[length];
  64. hunks_.push_back(p);
  65. return p;
  66. }
  67. private:
  68. std::vector<uint8_t*> hunks_;
  69. };
  70. const struct {
  71. uint32_t tag;
  72. bool (*parse)(ots::OpenTypeFile *otf, const uint8_t *data, size_t length);
  73. bool (*serialise)(ots::OTSStream *out, ots::OpenTypeFile *file);
  74. bool (*should_serialise)(ots::OpenTypeFile *file);
  75. void (*free)(ots::OpenTypeFile *file);
  76. bool required;
  77. } table_parsers[] = {
  78. { Tag("maxp"), ots::ots_maxp_parse, ots::ots_maxp_serialise,
  79. ots::ots_maxp_should_serialise, ots::ots_maxp_free, true },
  80. { Tag("head"), ots::ots_head_parse, ots::ots_head_serialise,
  81. ots::ots_head_should_serialise, ots::ots_head_free, true },
  82. { Tag("OS/2"), ots::ots_os2_parse, ots::ots_os2_serialise,
  83. ots::ots_os2_should_serialise, ots::ots_os2_free, true },
  84. { Tag("cmap"), ots::ots_cmap_parse, ots::ots_cmap_serialise,
  85. ots::ots_cmap_should_serialise, ots::ots_cmap_free, true },
  86. { Tag("hhea"), ots::ots_hhea_parse, ots::ots_hhea_serialise,
  87. ots::ots_hhea_should_serialise, ots::ots_hhea_free, true },
  88. { Tag("hmtx"), ots::ots_hmtx_parse, ots::ots_hmtx_serialise,
  89. ots::ots_hmtx_should_serialise, ots::ots_hmtx_free, true },
  90. { Tag("name"), ots::ots_name_parse, ots::ots_name_serialise,
  91. ots::ots_name_should_serialise, ots::ots_name_free, true },
  92. { Tag("post"), ots::ots_post_parse, ots::ots_post_serialise,
  93. ots::ots_post_should_serialise, ots::ots_post_free, true },
  94. { Tag("loca"), ots::ots_loca_parse, ots::ots_loca_serialise,
  95. ots::ots_loca_should_serialise, ots::ots_loca_free, false },
  96. { Tag("glyf"), ots::ots_glyf_parse, ots::ots_glyf_serialise,
  97. ots::ots_glyf_should_serialise, ots::ots_glyf_free, false },
  98. { Tag("CFF "), ots::ots_cff_parse, ots::ots_cff_serialise,
  99. ots::ots_cff_should_serialise, ots::ots_cff_free, false },
  100. { Tag("VDMX"), ots::ots_vdmx_parse, ots::ots_vdmx_serialise,
  101. ots::ots_vdmx_should_serialise, ots::ots_vdmx_free, false },
  102. { Tag("hdmx"), ots::ots_hdmx_parse, ots::ots_hdmx_serialise,
  103. ots::ots_hdmx_should_serialise, ots::ots_hdmx_free, false },
  104. { Tag("gasp"), ots::ots_gasp_parse, ots::ots_gasp_serialise,
  105. ots::ots_gasp_should_serialise, ots::ots_gasp_free, false },
  106. { Tag("cvt "), ots::ots_cvt_parse, ots::ots_cvt_serialise,
  107. ots::ots_cvt_should_serialise, ots::ots_cvt_free, false },
  108. { Tag("fpgm"), ots::ots_fpgm_parse, ots::ots_fpgm_serialise,
  109. ots::ots_fpgm_should_serialise, ots::ots_fpgm_free, false },
  110. { Tag("prep"), ots::ots_prep_parse, ots::ots_prep_serialise,
  111. ots::ots_prep_should_serialise, ots::ots_prep_free, false },
  112. { Tag("LTSH"), ots::ots_ltsh_parse, ots::ots_ltsh_serialise,
  113. ots::ots_ltsh_should_serialise, ots::ots_ltsh_free, false },
  114. { Tag("VORG"), ots::ots_vorg_parse, ots::ots_vorg_serialise,
  115. ots::ots_vorg_should_serialise, ots::ots_vorg_free, false },
  116. { Tag("kern"), ots::ots_kern_parse, ots::ots_kern_serialise,
  117. ots::ots_kern_should_serialise, ots::ots_kern_free, false },
  118. // We need to parse GDEF table in advance of parsing GSUB/GPOS tables
  119. // because they could refer GDEF table.
  120. { Tag("GDEF"), ots::ots_gdef_parse, ots::ots_gdef_serialise,
  121. ots::ots_gdef_should_serialise, ots::ots_gdef_free, false },
  122. { Tag("GPOS"), ots::ots_gpos_parse, ots::ots_gpos_serialise,
  123. ots::ots_gpos_should_serialise, ots::ots_gpos_free, false },
  124. { Tag("GSUB"), ots::ots_gsub_parse, ots::ots_gsub_serialise,
  125. ots::ots_gsub_should_serialise, ots::ots_gsub_free, false },
  126. { Tag("vhea"), ots::ots_vhea_parse, ots::ots_vhea_serialise,
  127. ots::ots_vhea_should_serialise, ots::ots_vhea_free, false },
  128. { Tag("vmtx"), ots::ots_vmtx_parse, ots::ots_vmtx_serialise,
  129. ots::ots_vmtx_should_serialise, ots::ots_vmtx_free, false },
  130. // TODO(bashi): Support mort, base, and jstf tables.
  131. { 0, NULL, NULL, NULL, NULL, false },
  132. };
  133. bool IsValidVersionTag(uint32_t tag) {
  134. return tag == Tag("\x00\x01\x00\x00") ||
  135. // OpenType fonts with CFF data have 'OTTO' tag.
  136. tag == Tag("OTTO") ||
  137. // Older Mac fonts might have 'true' or 'typ1' tag.
  138. tag == Tag("true") ||
  139. tag == Tag("typ1");
  140. }
  141. bool ProcessGeneric(ots::OpenTypeFile *header, ots::OTSStream *output,
  142. const uint8_t *data, size_t length,
  143. const std::vector<OpenTypeTable>& tables,
  144. ots::Buffer& file);
  145. bool ProcessTTF(ots::OpenTypeFile *header,
  146. ots::OTSStream *output, const uint8_t *data, size_t length) {
  147. ots::Buffer file(data, length);
  148. // we disallow all files > 1GB in size for sanity.
  149. if (length > 1024 * 1024 * 1024) {
  150. return OTS_FAILURE();
  151. }
  152. if (!file.ReadTag(&header->version)) {
  153. return OTS_FAILURE();
  154. }
  155. if (!IsValidVersionTag(header->version)) {
  156. return OTS_FAILURE();
  157. }
  158. if (!file.ReadU16(&header->num_tables) ||
  159. !file.ReadU16(&header->search_range) ||
  160. !file.ReadU16(&header->entry_selector) ||
  161. !file.ReadU16(&header->range_shift)) {
  162. return OTS_FAILURE();
  163. }
  164. // search_range is (Maximum power of 2 <= numTables) x 16. Thus, to avoid
  165. // overflow num_tables is, at most, 2^16 / 16 = 2^12
  166. if (header->num_tables >= 4096 || header->num_tables < 1) {
  167. return OTS_FAILURE();
  168. }
  169. unsigned max_pow2 = 0;
  170. while (1u << (max_pow2 + 1) <= header->num_tables) {
  171. max_pow2++;
  172. }
  173. const uint16_t expected_search_range = (1u << max_pow2) << 4;
  174. // Don't call ots_failure() here since ~25% of fonts (250+ fonts) in
  175. // http://www.princexml.com/fonts/ have unexpected search_range value.
  176. if (header->search_range != expected_search_range) {
  177. OTS_WARNING("bad search range");
  178. header->search_range = expected_search_range; // Fix the value.
  179. }
  180. // entry_selector is Log2(maximum power of 2 <= numTables)
  181. if (header->entry_selector != max_pow2) {
  182. return OTS_FAILURE();
  183. }
  184. // range_shift is NumTables x 16-searchRange. We know that 16*num_tables
  185. // doesn't over flow because we range checked it above. Also, we know that
  186. // it's > header->search_range by construction of search_range.
  187. const uint32_t expected_range_shift
  188. = 16 * header->num_tables - header->search_range;
  189. if (header->range_shift != expected_range_shift) {
  190. OTS_WARNING("bad range shift");
  191. header->range_shift = expected_range_shift; // the same as above.
  192. }
  193. // Next up is the list of tables.
  194. std::vector<OpenTypeTable> tables;
  195. for (unsigned i = 0; i < header->num_tables; ++i) {
  196. OpenTypeTable table;
  197. if (!file.ReadTag(&table.tag) ||
  198. !file.ReadU32(&table.chksum) ||
  199. !file.ReadU32(&table.offset) ||
  200. !file.ReadU32(&table.length)) {
  201. return OTS_FAILURE();
  202. }
  203. table.uncompressed_length = table.length;
  204. tables.push_back(table);
  205. }
  206. return ProcessGeneric(header, output, data, length, tables, file);
  207. }
  208. bool ProcessWOFF(ots::OpenTypeFile *header,
  209. ots::OTSStream *output, const uint8_t *data, size_t length) {
  210. ots::Buffer file(data, length);
  211. // we disallow all files > 1GB in size for sanity.
  212. if (length > 1024 * 1024 * 1024) {
  213. return OTS_FAILURE();
  214. }
  215. uint32_t woff_tag;
  216. if (!file.ReadTag(&woff_tag)) {
  217. return OTS_FAILURE();
  218. }
  219. if (woff_tag != Tag("wOFF")) {
  220. return OTS_FAILURE();
  221. }
  222. if (!file.ReadTag(&header->version)) {
  223. return OTS_FAILURE();
  224. }
  225. if (!IsValidVersionTag(header->version)) {
  226. return OTS_FAILURE();
  227. }
  228. header->search_range = 0;
  229. header->entry_selector = 0;
  230. header->range_shift = 0;
  231. uint32_t reported_length;
  232. if (!file.ReadU32(&reported_length) || length != reported_length) {
  233. return OTS_FAILURE();
  234. }
  235. if (!file.ReadU16(&header->num_tables)) {
  236. return OTS_FAILURE();
  237. }
  238. uint16_t reserved_value;
  239. if (!file.ReadU16(&reserved_value) || reserved_value) {
  240. return OTS_FAILURE();
  241. }
  242. // We don't care about these fields of the header:
  243. // uint32_t uncompressed_size;
  244. // uint16_t major_version, minor_version
  245. // uint32_t meta_offset, meta_length, meta_length_orig
  246. // uint32_t priv_offset, priv_length
  247. if (!file.Skip(6 * 4 + 2 * 2)) {
  248. return OTS_FAILURE();
  249. }
  250. // Next up is the list of tables.
  251. std::vector<OpenTypeTable> tables;
  252. for (unsigned i = 0; i < header->num_tables; ++i) {
  253. OpenTypeTable table;
  254. if (!file.ReadTag(&table.tag) ||
  255. !file.ReadU32(&table.offset) ||
  256. !file.ReadU32(&table.length) ||
  257. !file.ReadU32(&table.uncompressed_length) ||
  258. !file.ReadU32(&table.chksum)) {
  259. return OTS_FAILURE();
  260. }
  261. tables.push_back(table);
  262. }
  263. return ProcessGeneric(header, output, data, length, tables, file);
  264. }
  265. bool ProcessGeneric(ots::OpenTypeFile *header, ots::OTSStream *output,
  266. const uint8_t *data, size_t length,
  267. const std::vector<OpenTypeTable>& tables,
  268. ots::Buffer& file) {
  269. const size_t data_offset = file.offset();
  270. uint32_t uncompressed_sum = 0;
  271. for (unsigned i = 0; i < header->num_tables; ++i) {
  272. // the tables must be sorted by tag (when taken as big-endian numbers).
  273. // This also remove the possibility of duplicate tables.
  274. if (i) {
  275. const uint32_t this_tag = ntohl(tables[i].tag);
  276. const uint32_t prev_tag = ntohl(tables[i - 1].tag);
  277. if (this_tag <= prev_tag) {
  278. return OTS_FAILURE();
  279. }
  280. }
  281. // all tag names must be built from printable ASCII characters
  282. if (!CheckTag(tables[i].tag)) {
  283. return OTS_FAILURE();
  284. }
  285. // tables must be 4-byte aligned
  286. if (tables[i].offset & 3) {
  287. return OTS_FAILURE();
  288. }
  289. // and must be within the file
  290. if (tables[i].offset < data_offset || tables[i].offset >= length) {
  291. return OTS_FAILURE();
  292. }
  293. // disallow all tables with a zero length
  294. if (tables[i].length < 1) {
  295. // Note: malayalam.ttf has zero length CVT table...
  296. return OTS_FAILURE();
  297. }
  298. // disallow all tables with a length > 1GB
  299. if (tables[i].length > 1024 * 1024 * 1024) {
  300. return OTS_FAILURE();
  301. }
  302. // disallow tables where the uncompressed size is < the compressed size.
  303. if (tables[i].uncompressed_length < tables[i].length) {
  304. return OTS_FAILURE();
  305. }
  306. if (tables[i].uncompressed_length > tables[i].length) {
  307. // We'll probably be decompressing this table.
  308. // disallow all tables which uncompress to > 30 MB
  309. if (tables[i].uncompressed_length > 30 * 1024 * 1024) {
  310. return OTS_FAILURE();
  311. }
  312. if (uncompressed_sum + tables[i].uncompressed_length < uncompressed_sum) {
  313. return OTS_FAILURE();
  314. }
  315. uncompressed_sum += tables[i].uncompressed_length;
  316. }
  317. // since we required that the file be < 1GB in length, and that the table
  318. // length is < 1GB, the following addtion doesn't overflow
  319. const uint32_t end_byte = Round4(tables[i].offset + tables[i].length);
  320. // Some fonts which are automatically generated by a font generator
  321. // called TTX seems not to add 0-padding to the final table. It might be
  322. // ok to accept these fonts so we round up the length of the font file.
  323. if (!end_byte || end_byte > Round4(length)) {
  324. return OTS_FAILURE();
  325. }
  326. }
  327. // All decompressed tables uncompressed must be <= 30MB.
  328. if (uncompressed_sum > 30 * 1024 * 1024) {
  329. return OTS_FAILURE();
  330. }
  331. std::map<uint32_t, OpenTypeTable> table_map;
  332. for (unsigned i = 0; i < header->num_tables; ++i) {
  333. table_map[tables[i].tag] = tables[i];
  334. }
  335. // check that the tables are not overlapping.
  336. std::vector<std::pair<uint32_t, uint8_t> > overlap_checker;
  337. for (unsigned i = 0; i < header->num_tables; ++i) {
  338. overlap_checker.push_back(
  339. std::make_pair(tables[i].offset, 1 /* start */));
  340. overlap_checker.push_back(
  341. std::make_pair(tables[i].offset + tables[i].length, 0 /* end */));
  342. }
  343. std::sort(overlap_checker.begin(), overlap_checker.end());
  344. int overlap_count = 0;
  345. for (unsigned i = 0; i < overlap_checker.size(); ++i) {
  346. overlap_count += (overlap_checker[i].second ? 1 : -1);
  347. if (overlap_count > 1) {
  348. return OTS_FAILURE();
  349. }
  350. }
  351. Arena arena;
  352. for (unsigned i = 0; ; ++i) {
  353. if (table_parsers[i].parse == NULL) break;
  354. const std::map<uint32_t, OpenTypeTable>::const_iterator it
  355. = table_map.find(table_parsers[i].tag);
  356. if (it == table_map.end()) {
  357. if (table_parsers[i].required) {
  358. return OTS_FAILURE();
  359. }
  360. continue;
  361. }
  362. const uint8_t* table_data;
  363. size_t table_length;
  364. if (it->second.uncompressed_length != it->second.length) {
  365. // compressed table. Need to uncompress into memory first.
  366. table_length = it->second.uncompressed_length;
  367. table_data = arena.Allocate(table_length);
  368. uLongf dest_len = table_length;
  369. int r = uncompress((Bytef*) table_data, &dest_len,
  370. data + it->second.offset, it->second.length);
  371. if (r != Z_OK || dest_len != table_length) {
  372. return OTS_FAILURE();
  373. }
  374. } else {
  375. // uncompressed table. We can process directly from memory.
  376. table_data = data + it->second.offset;
  377. table_length = it->second.length;
  378. }
  379. if (!table_parsers[i].parse(header, table_data, table_length)) {
  380. return OTS_FAILURE();
  381. }
  382. }
  383. if (header->cff) {
  384. // font with PostScript glyph
  385. if (header->version != Tag("OTTO")) {
  386. return OTS_FAILURE();
  387. }
  388. if (header->glyf || header->loca) {
  389. // mixing outline formats is not recommended
  390. return OTS_FAILURE();
  391. }
  392. } else {
  393. if (!header->glyf || !header->loca) {
  394. // No TrueType glyph found.
  395. // Note: bitmap-only fonts are not supported.
  396. return OTS_FAILURE();
  397. }
  398. }
  399. unsigned num_output_tables = 0;
  400. for (unsigned i = 0; ; ++i) {
  401. if (table_parsers[i].parse == NULL) {
  402. break;
  403. }
  404. if (table_parsers[i].should_serialise(header)) {
  405. num_output_tables++;
  406. }
  407. }
  408. unsigned max_pow2 = 0;
  409. while (1u << (max_pow2 + 1) <= num_output_tables) {
  410. max_pow2++;
  411. }
  412. const uint16_t output_search_range = (1u << max_pow2) << 4;
  413. output->ResetChecksum();
  414. if (!output->WriteTag(header->version) ||
  415. !output->WriteU16(num_output_tables) ||
  416. !output->WriteU16(output_search_range) ||
  417. !output->WriteU16(max_pow2) ||
  418. !output->WriteU16((num_output_tables << 4) - output_search_range)) {
  419. return OTS_FAILURE();
  420. }
  421. const uint32_t offset_table_chksum = output->chksum();
  422. const size_t table_record_offset = output->Tell();
  423. if (!output->Pad(16 * num_output_tables)) {
  424. return OTS_FAILURE();
  425. }
  426. std::vector<OutputTable> out_tables;
  427. size_t head_table_offset = 0;
  428. for (unsigned i = 0; ; ++i) {
  429. if (table_parsers[i].parse == NULL) {
  430. break;
  431. }
  432. if (!table_parsers[i].should_serialise(header)) {
  433. continue;
  434. }
  435. OutputTable out;
  436. out.tag = table_parsers[i].tag;
  437. out.offset = output->Tell();
  438. output->ResetChecksum();
  439. if (table_parsers[i].tag == Tag("head")) {
  440. head_table_offset = out.offset;
  441. }
  442. if (!table_parsers[i].serialise(output, header)) {
  443. return OTS_FAILURE();
  444. }
  445. const size_t end_offset = output->Tell();
  446. if (end_offset <= out.offset) {
  447. // paranoid check. |end_offset| is supposed to be greater than the offset,
  448. // as long as the Tell() interface is implemented correctly.
  449. return OTS_FAILURE();
  450. }
  451. out.length = end_offset - out.offset;
  452. // align tables to four bytes
  453. if (!output->Pad((4 - (end_offset & 3)) % 4)) {
  454. return OTS_FAILURE();
  455. }
  456. out.chksum = output->chksum();
  457. out_tables.push_back(out);
  458. }
  459. const size_t end_of_file = output->Tell();
  460. // Need to sort the output tables for inclusion in the file
  461. std::sort(out_tables.begin(), out_tables.end(), OutputTable::SortByTag);
  462. if (!output->Seek(table_record_offset)) {
  463. return OTS_FAILURE();
  464. }
  465. output->ResetChecksum();
  466. uint32_t tables_chksum = 0;
  467. for (unsigned i = 0; i < out_tables.size(); ++i) {
  468. if (!output->WriteTag(out_tables[i].tag) ||
  469. !output->WriteU32(out_tables[i].chksum) ||
  470. !output->WriteU32(out_tables[i].offset) ||
  471. !output->WriteU32(out_tables[i].length)) {
  472. return OTS_FAILURE();
  473. }
  474. tables_chksum += out_tables[i].chksum;
  475. }
  476. const uint32_t table_record_chksum = output->chksum();
  477. // http://www.microsoft.com/typography/otspec/otff.htm
  478. const uint32_t file_chksum
  479. = offset_table_chksum + tables_chksum + table_record_chksum;
  480. const uint32_t chksum_magic = static_cast<uint32_t>(0xb1b0afba) - file_chksum;
  481. // seek into the 'head' table and write in the checksum magic value
  482. if (!head_table_offset) {
  483. return OTS_FAILURE(); // not reached.
  484. }
  485. if (!output->Seek(head_table_offset + 8)) {
  486. return OTS_FAILURE();
  487. }
  488. if (!output->WriteU32(chksum_magic)) {
  489. return OTS_FAILURE();
  490. }
  491. if (!output->Seek(end_of_file)) {
  492. return OTS_FAILURE();
  493. }
  494. return true;
  495. }
  496. } // namespace
  497. namespace ots {
  498. void DisableDebugOutput() {
  499. g_debug_output = false;
  500. }
  501. bool Process(OTSStream *output, const uint8_t *data, size_t length) {
  502. OpenTypeFile header;
  503. if (length < 4) {
  504. return OTS_FAILURE();
  505. }
  506. bool result;
  507. if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') {
  508. result = ProcessWOFF(&header, output, data, length);
  509. } else {
  510. result = ProcessTTF(&header, output, data, length);
  511. }
  512. for (unsigned i = 0; ; ++i) {
  513. if (table_parsers[i].parse == NULL) break;
  514. table_parsers[i].free(&header);
  515. }
  516. return result;
  517. }
  518. #if !defined(_MSC_VER) && defined(OTS_DEBUG)
  519. bool Failure(const char *f, int l, const char *fn) {
  520. if (g_debug_output) {
  521. std::fprintf(stderr, "ERROR at %s:%d (%s)\n", f, l, fn);
  522. std::fflush(stderr);
  523. }
  524. return false;
  525. }
  526. void Warning(const char *f, int l, const char *format, ...) {
  527. if (g_debug_output) {
  528. std::fprintf(stderr, "WARNING at %s:%d: ", f, l);
  529. std::va_list va;
  530. va_start(va, format);
  531. std::vfprintf(stderr, format, va);
  532. va_end(va);
  533. std::fprintf(stderr, "\n");
  534. std::fflush(stderr);
  535. }
  536. }
  537. #endif
  538. } // namespace ots