BUG: Token array now terminated by \0

This commit is contained in:
Yannick Reiß 2023-10-21 00:36:12 +02:00
parent 075cfddcaf
commit 5d5b4d93d7
No known key found for this signature in database
GPG Key ID: 5A3AF456F0A0338C
3 changed files with 10 additions and 4 deletions

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
/** /**
* @name analyze * @name analyze
@ -10,7 +11,8 @@
* @brief Analyze the tokens syntax. Return -1 on error and 1 on warning, 0 else. * @brief Analyze the tokens syntax. Return -1 on error and 1 on warning, 0 else.
* *
* @param char* tokens: analyze_tokens * @param char* tokens: analyze_tokens
* @param char* device: target device
*/ */
int analyze (char* tokens); int analyze (char* tokens, char* device);
#endif//ANALYZER_H #endif//ANALYZER_H

View File

@ -6,8 +6,9 @@
* @brief Check for errors and warnings. * @brief Check for errors and warnings.
* *
* @param char* token * @param char* token
* @param char* device
*/ */
int analyze (char* token) { int analyze (char* token, char* device) {
int rv = 0; int rv = 0;
int position = 0; int position = 0;
@ -28,8 +29,8 @@ int analyze (char* token) {
break; break;
} }
/* check for nested loops */ /* check for nested loops in case of using the logisim model */
if (rv > 1) { if (rv > 1 && !strcmp(device, "logisim")) {
(void)printf("Warning on token %d\n", position); (void)printf("Warning on token %d\n", position);
(void)printf("WARNING: Nested loops are not supported on all versions of the target device!\n"); (void)printf("WARNING: Nested loops are not supported on all versions of the target device!\n");
} }

View File

@ -38,6 +38,9 @@ int extractTokens (char* buffer, char* tokens) {
} }
/* Terminate the array using a null character */
tokens[tokens_found] = 0; /* same as \0 */
rv = tokens_found; rv = tokens_found;
return rv; return rv;