排错-Error--memory violation Exception ACCESS_VIOLATION received解决方

简介: 排错-Error--memory violation Exception ACCESS_VIOLATION received解决方

Error -- memory violation : Exception ACCESS_VIOLATION received

 


测试代码:

Action()

{

   char *a = NULL;

   strcpy(a, "shouke");

   return 0;

}

 

运行报错:

Action.c(4): Error: C interpreter run time error: Action.c (4):  Error -- memory violation : Exception ACCESS_VIOLATION received.

Action.c(4): Notify: CCI trace: Action.c(4): strcpy(0x00000000, 0x032b0111 "shouke")

.

Action.c(4): Notify: CCI trace: Compiled_code(0): Action()

 

原因分析:

char *a = NULL; a为指向栈内存的指针,暂时值为NULL,指向内存为空。所以,不能用于存放内容。

 

改正方法:

法一,用数组开辟栈内存

Action()

{

   #char *a = NULL;

   char a[20]={0};

   strcpy(a, "shouke");

   return 0;

}

 

法二,开辟堆内存:

Action()

{

   char *a = NULL;

   a = (char *)malloc(sizeof(char)*20);

   strcpy(a, "shouke");

   free(a);

   a = NULL;

   return 0;

}

目录
相关文章
运行JProfiler:ERROR: Invalid license key. Aborting
运行JProfiler:ERROR: Invalid license key. Aborting
443 0
运行JProfiler:ERROR: Invalid license key. Aborting
|
4月前
|
Shell 网络安全 开发工具
fatal: unable to access 'https://github.com/wolfcw/libfaketime.git/': Encountered end of file
fatal: unable to access 'https://github.com/wolfcw/libfaketime.git/': Encountered end of file
|
6月前
|
网络协议 网络安全 数据库
|
5月前
|
iOS开发 Perl
解決pod install报错:unable to access: LibreSSL SSL_read: error:Operation timed out, errno 60
解決pod install报错:unable to access: LibreSSL SSL_read: error:Operation timed out, errno 60
108 0
|
8月前
An unexpected error was encountered while executing a WSL command. Common causes include access righ
An unexpected error was encountered while executing a WSL command. Common causes include access righ
|
8月前
|
应用服务中间件 nginx Windows
[emerg] 15060#200: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket ......
[emerg] 15060#200: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket ......
239 0
|
Java Maven
An attempt was made to call a method that does not exist. The attempt was made from the following
An attempt was made to call a method that does not exist. The attempt was made from the following
510 0
abort: error: Temporary failure in name resolution
abort: error: Temporary failure in name resolution
205 0
configure: error: You requested LIBYUV but not found...die
configure: error: You requested LIBYUV but not found...die
111 0