ef4cb2bf74
Re-enable cppcheck CI job
Update cppcheck suppression list:
The new version of cppcheck raises warnings for many potential
issues that are guarded against, so those warnings have been
supressed.
Handle realloc failures:
- jerry-ext/util/sources.c
- jerry-port/common/jerry-port-io.c
Refactor test-snapshot: move each test to separate functions like some
others already were.
Rename `handler` variables inside `main` of `test-api.c` as they
shadowed the `handler` function in the same file.
JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi mate.tokodi@szteszoftver.hu
111 lines
2.8 KiB
C
111 lines
2.8 KiB
C
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "jerryscript-port.h"
|
|
|
|
/**
|
|
* Default implementation of jerry_port_log. Prints log messages to stderr.
|
|
*/
|
|
void JERRY_ATTR_WEAK
|
|
jerry_port_log (const char *message_p) /**< message */
|
|
{
|
|
fputs (message_p, stderr);
|
|
} /* jerry_port_log */
|
|
|
|
/**
|
|
* Default implementation of jerry_port_print_byte. Uses 'putchar' to
|
|
* print a single character to standard output.
|
|
*/
|
|
void JERRY_ATTR_WEAK
|
|
jerry_port_print_byte (jerry_char_t byte) /**< the character to print */
|
|
{
|
|
putchar (byte);
|
|
} /* jerry_port_print_byte */
|
|
|
|
/**
|
|
* Default implementation of jerry_port_print_buffer. Uses 'jerry_port_print_byte' to
|
|
* print characters of the input buffer.
|
|
*/
|
|
void JERRY_ATTR_WEAK
|
|
jerry_port_print_buffer (const jerry_char_t *buffer_p, /**< string buffer */
|
|
jerry_size_t buffer_size) /**< string size*/
|
|
{
|
|
for (jerry_size_t i = 0; i < buffer_size; i++)
|
|
{
|
|
jerry_port_print_byte (buffer_p[i]);
|
|
}
|
|
} /* jerry_port_print_byte */
|
|
|
|
/**
|
|
* Read a line from standard input as a zero-terminated string.
|
|
*
|
|
* @param out_size_p: length of the string
|
|
*
|
|
* @return pointer to the buffer storing the string,
|
|
* or NULL if end of input
|
|
*/
|
|
jerry_char_t *JERRY_ATTR_WEAK
|
|
jerry_port_line_read (jerry_size_t *out_size_p)
|
|
{
|
|
char *line_p = NULL;
|
|
size_t allocated = 0;
|
|
size_t bytes = 0;
|
|
|
|
while (true)
|
|
{
|
|
allocated += 64;
|
|
line_p = realloc (line_p, allocated);
|
|
if (line_p == NULL)
|
|
{
|
|
jerry_port_fatal (JERRY_FATAL_OUT_OF_MEMORY);
|
|
}
|
|
|
|
while (bytes < allocated - 1)
|
|
{
|
|
char ch = (char) fgetc (stdin);
|
|
|
|
if (feof (stdin))
|
|
{
|
|
free (line_p);
|
|
return NULL;
|
|
}
|
|
|
|
line_p[bytes++] = ch;
|
|
|
|
if (ch == '\n')
|
|
{
|
|
*out_size_p = (jerry_size_t) bytes;
|
|
line_p[bytes++] = '\0';
|
|
return (jerry_char_t *) line_p;
|
|
}
|
|
}
|
|
}
|
|
} /* jerry_port_line_read */
|
|
|
|
/**
|
|
* Free a line buffer allocated by jerry_port_line_read
|
|
*
|
|
* @param buffer_p: buffer that has been allocated by jerry_port_line_read
|
|
*/
|
|
void JERRY_ATTR_WEAK
|
|
jerry_port_line_free (jerry_char_t *buffer_p)
|
|
{
|
|
free (buffer_p);
|
|
} /* jerry_port_line_free */
|