Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/bindings.ipp

Issue 29404594: Noissue - [emscripten] Replace sprintf() usage by safe alternatives (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created April 6, 2017, 8:40 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | compiled/filter/ActiveFilter.cpp » ('j') | compiled/filter/ActiveFilter.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 result += " else\n"; 450 result += " else\n";
451 result += " result = null;\n"; 451 result += " result = null;\n";
452 return result; 452 return result;
453 } 453 }
454 else 454 else
455 throw std::runtime_error("Unexpected return type for " + std::string(call. name)); 455 throw std::runtime_error("Unexpected return type for " + std::string(call. name));
456 } 456 }
457 457
458 const std::string wrapCall(const FunctionInfo& call) 458 const std::string wrapCall(const FunctionInfo& call)
459 { 459 {
460 char buffer[20];
461 bool hasStringArgs = false; 460 bool hasStringArgs = false;
462 std::vector<std::string> params; 461 std::vector<std::string> params;
463 std::string prefix = "function("; 462 std::string prefix = "function(";
464 for (int i = 0; i < call.args.size(); i++) 463 for (int i = 0; i < call.args.size(); i++)
465 { 464 {
466 sprintf(buffer, "arg%i", i); 465 std::string argName("arg" + std::to_string(i));
467 if (i > 0) 466 if (i > 0)
468 prefix += ", "; 467 prefix += ", ";
469 prefix += buffer; 468 prefix += argName;
470 469
471 if (call.args[i] == TypeCategory::STRING_REF) 470 if (call.args[i] == TypeCategory::STRING_REF)
472 { 471 {
473 hasStringArgs = true; 472 hasStringArgs = true;
474 params.push_back(std::string("createString(") + buffer + ")"); 473 params.push_back(std::string("createString(") + argName + ")");
475 } 474 }
476 else if (call.args[i] == TypeCategory::CLASS_PTR) 475 else if (call.args[i] == TypeCategory::CLASS_PTR)
477 params.push_back(std::string(buffer) + "._pointer"); 476 params.push_back(argName + "._pointer");
478 else 477 else
479 params.push_back(buffer); 478 params.push_back(argName);
480 } 479 }
481 prefix += ")\n{\n"; 480 prefix += ")\n{\n";
482 481
483 std::string suffix = "}"; 482 std::string suffix = "}";
484 if (call.returnType != TypeCategory::VOID) 483 if (call.returnType != TypeCategory::VOID)
485 suffix = " return result;\n" + suffix; 484 suffix = " return result;\n" + suffix;
486 485
487 if (call.returnType == TypeCategory::DEPENDENT_STRING || 486 if (call.returnType == TypeCategory::DEPENDENT_STRING ||
488 call.returnType == TypeCategory::OWNED_STRING || hasStringArgs) 487 call.returnType == TypeCategory::OWNED_STRING || hasStringArgs)
489 { 488 {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 bindings_internal::register_differentiator( 757 bindings_internal::register_differentiator(
759 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 758 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
760 return *this; 759 return *this;
761 } 760 }
762 }; 761 };
763 762
764 void custom_generator(bindings_internal::CustomGenerator generator) 763 void custom_generator(bindings_internal::CustomGenerator generator)
765 { 764 {
766 bindings_internal::customGenerators.push_back(generator); 765 bindings_internal::customGenerators.push_back(generator);
767 } 766 }
OLDNEW
« no previous file with comments | « no previous file | compiled/filter/ActiveFilter.cpp » ('j') | compiled/filter/ActiveFilter.cpp » ('J')

Powered by Google App Engine
This is Rietveld