Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix string buffer bugs #8

Merged
merged 3 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ LibDriver INA219 is the full function driver of INA219 launched by LibDriver.It

/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.

/misra includes the LibDriver MISRA code scanning results.

### Install

Reference /interface IIC platform independent template and finish your platform IIC driver.
Expand Down
2 changes: 2 additions & 0 deletions README_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ LibDriver INA219 ist der voll funktionsfähige Treiber von INA219, der von LibDr

/project enthält den allgemeinen Beispielcode für Linux- und MCU-Entwicklungsboards. Alle Projekte verwenden das Shell-Skript, um den Treiber zu debuggen, und die detaillierten Anweisungen finden Sie in der README.md jedes Projekts.

/misra enthält die Ergebnisse des LibDriver MISRA Code Scans.

### Installieren

Verweisen Sie auf eine plattformunabhängige IIC-Schnittstellenvorlage und stellen Sie Ihren Plattform-IIC-Treiber fertig.
Expand Down
2 changes: 2 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ LibDriver INA219は、LibDriverによって発売されたINA219の全機能ド

/ projectディレクトリには、一般的に使用されるLinuxおよびマイクロコントローラー開発ボードのプロジェクトサンプルが含まれています。 すべてのプロジェクトは、デバッグ方法としてシェルスクリプトを使用しています。詳細については、各プロジェクトのREADME.mdを参照してください。

/ misraはLibDriver misraコードスキャン結果を含む。

### インストール

/ interfaceディレクトリにあるプラットフォームに依存しないIICバステンプレートを参照して、指定したプラットフォームのIICバスドライバを完成させます。
Expand Down
2 changes: 2 additions & 0 deletions README_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ LibDriver INA219는 LibDriver에서 출시한 INA219의 전체 기능 드라이

/project 디렉토리에는 일반적으로 사용되는 Linux 및 마이크로컨트롤러 개발 보드의 프로젝트 샘플이 포함되어 있습니다. 모든 프로젝트는 디버깅 방법으로 셸 스크립트를 사용하며, 자세한 내용은 각 프로젝트의 README.md를 참조하십시오.

/misra 에는 LibDriver misra 코드 검색 결과가 포함됩니다.

### 설치

/interface 디렉토리에서 플랫폼 독립적인 IIC버스 템플릿을 참조하여 지정된 플랫폼에 대한 IIC버스 드라이버를 완성하십시오.
Expand Down
2 changes: 2 additions & 0 deletions README_zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ LibDriver INA219是LibDriver推出的INA219的全功能驱动,该驱动提供

/project目录包含了常用Linux与单片机开发板的工程样例。所有工程均采用shell脚本作为调试方法,详细内容可参考每个工程里面的README.md。

/misra目录包含了LibDriver MISRA代码扫描结果。

### 安装

参考/interface目录下与平台无关的IIC总线模板,完成指定平台的IIC总线驱动。
Expand Down
2 changes: 2 additions & 0 deletions README_zh-Hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ LibDriver INA219是LibDriver推出的INA219的全功能驅動,該驅動提供

/project目錄包含了常用Linux與單片機開發板的工程樣例。所有工程均採用shell腳本作為調試方法,詳細內容可參考每個工程裡面的README.md。

/misra目錄包含了LibDriver MISRA程式碼掃描結果。

### 安裝

參考/interface目錄下與平台無關的IIC總線模板,完成指定平台的IIC總線驅動。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ void ina219_interface_delay_ms(uint32_t ms)
void ina219_interface_debug_print(const char *const fmt, ...)
{
char str[256];
uint8_t len;
uint16_t len;
va_list args;

memset((char *)str, 0, sizeof(char) * 256);
va_start(args, fmt);
vsnprintf((char *)str, 256, (char const *)fmt, args);
vsnprintf((char *)str, 255, (char const *)fmt, args);
va_end(args);

len = strlen((char *)str);
(void)printf((uint8_t *)str, len);
}
18 changes: 9 additions & 9 deletions project/raspberrypi4b/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
* @param[in] argc is arg numbers
* @param[in] **argv is the arg address
* @return status code
* - 0 success
* - 1 run failed
* - 5 param is invalid
* - 0 success
* - 1 run failed
* - 5 param is invalid
* @note none
*/
uint8_t ina219(uint8_t argc, char **argv)
Expand All @@ -68,7 +68,7 @@ uint8_t ina219(uint8_t argc, char **argv)
{"times", required_argument, NULL, 3},
{NULL, 0, NULL, 0},
};
char type[32] = "unknow";
char type[33] = "unknow";
uint32_t times = 3;
double r = 0.1;
ina219_address_t addr = INA219_ADDRESS_0;
Expand Down Expand Up @@ -96,7 +96,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'h' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "h");

break;
Expand All @@ -106,7 +106,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'i' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "i");

break;
Expand All @@ -116,7 +116,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'p' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "p");

break;
Expand All @@ -126,7 +126,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'e' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "e_%s", optarg);

break;
Expand All @@ -136,7 +136,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 't' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "t_%s", optarg);

break;
Expand Down
9 changes: 8 additions & 1 deletion project/stm32f407/EW/stm32f407.dep
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
<fileChecksum>2154371921</fileChecksum>
<configuration>
<name>Release</name>
<outputs />
<outputs>
<file>$PROJ_DIR$\..\usr\src\main.c</file>
<file>$PROJ_DIR$\..\usr\src\system_stm32f4xx.c</file>
<file>$PROJ_DIR$\..\usr\src\stm32f4xx_hal_msp.c</file>
<file>$PROJ_DIR$\..\usr\src\shell.c</file>
<file>$PROJ_DIR$\..\usr\src\getopt.c</file>
<file>$PROJ_DIR$\..\usr\src\stm32f4xx_it.c</file>
</outputs>
<forcedrebuild>
<name>[REBUILD_ALL]</name>
</forcedrebuild>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ void ina219_interface_delay_ms(uint32_t ms)
void ina219_interface_debug_print(const char *const fmt, ...)
{
char str[256];
uint8_t len;
uint16_t len;
va_list args;

memset((char *)str, 0, sizeof(char) * 256);
va_start(args, fmt);
vsnprintf((char *)str, 256, (char const *)fmt, args);
vsnprintf((char *)str, 255, (char const *)fmt, args);
va_end(args);

len = strlen((char *)str);
Expand Down
4 changes: 2 additions & 2 deletions project/stm32f407/interface/src/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ uint16_t uart_flush(void)
uint16_t uart_print(const char *const fmt, ...)
{
char str[256];
uint8_t len;
uint16_t len;
va_list args;

/* print to the buffer */
memset((char *)str, 0, sizeof(char) * 256);
va_start(args, fmt);
vsnprintf((char *)str, 256, (char const *)fmt, args);
vsnprintf((char *)str, 255, (char const *)fmt, args);
va_end(args);

/* send the data */
Expand Down
18 changes: 9 additions & 9 deletions project/stm32f407/usr/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ volatile uint16_t g_len; /**< uart buffer length */
* @param[in] argc is arg numbers
* @param[in] **argv is the arg address
* @return status code
* - 0 success
* - 1 run failed
* - 5 param is invalid
* - 0 success
* - 1 run failed
* - 5 param is invalid
* @note none
*/
uint8_t ina219(uint8_t argc, char **argv)
Expand All @@ -78,7 +78,7 @@ uint8_t ina219(uint8_t argc, char **argv)
{"times", required_argument, NULL, 3},
{NULL, 0, NULL, 0},
};
char type[32] = "unknow";
char type[33] = "unknow";
uint32_t times = 3;
double r = 0.1;
ina219_address_t addr = INA219_ADDRESS_0;
Expand Down Expand Up @@ -106,7 +106,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'h' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "h");

break;
Expand All @@ -116,7 +116,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'i' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "i");

break;
Expand All @@ -126,7 +126,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'p' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "p");

break;
Expand All @@ -136,7 +136,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 'e' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "e_%s", optarg);

break;
Expand All @@ -146,7 +146,7 @@ uint8_t ina219(uint8_t argc, char **argv)
case 't' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "t_%s", optarg);

break;
Expand Down