[apps/code] Handle too many Script default names used

When adding to many scripts without naming them, one can overflow the
number of default generated script names, in which case we force the
user to enter a name.
This commit is contained in:
Léa Saviot
2018-11-05 17:58:42 +01:00
committed by Émilie Feral
parent 0f9d1db851
commit e74e15eaf7
5 changed files with 32 additions and 20 deletions

View File

@@ -18,23 +18,23 @@ static inline void intToText(int i, char * buffer, int bufferSize) {
buffer[2] = 0;
}
void Script::DefaultName(char buffer[], size_t bufferSize) {
bool Script::DefaultName(char buffer[], size_t bufferSize) {
assert(bufferSize >= k_defaultScriptNameMaxSize);
static constexpr char defaultScriptName[] = "script";
static constexpr int defaultScriptNameLength = 6;
memcpy(buffer, defaultScriptName, bufferSize);
// We will only name scripts from script1.py to script99.py.
int currentScriptNumber = 1;
while (currentScriptNumber < 100) {
while (currentScriptNumber <= k_maxNumberOfDefaultScriptNames) {
// Change the number in the script name.
intToText(currentScriptNumber, &buffer[defaultScriptNameLength], bufferSize - defaultScriptNameLength );
if (ScriptStore::ScriptNameIsFree(buffer)) {
return;
return true;
}
currentScriptNumber++;
}
assert(false);
// We did not find a new script name
return false;
}
bool Script::nameCompliant(const char * name) {