This code works fine and also produces the required output, but it results to this window popping-up in the end.
As it can be seen, no errors or warnings are mentioned. I wish to rectify this. It is definitely not stuck in a loop, since it properly returns the required value. What could be the reason behind this issue? Please help.
Here's the code:
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define size 10000
int max(int a, int b)
{
if(a>b)
return a;
return b;
}
int find_subseq(char *a, char *b)
{
int i, j, la = strlen(a), lb = strlen(b);
int *arr = (int *)malloc(((la+1)*(lb+1)*sizeof(char)));
for(i = 0; i < la; i+=(lb+1))
{
*(arr+i) = 0;
}
for(j = 0; j < lb+1; j++)
{
*(arr+j) = 0;
}
for(i = 1; i <= la; i++)
{
for(j = 1; j <= lb; j++)
{
if(*(a+i) == *(b+j))
*(arr+i*lb+j) = *(arr+i*(lb-1)+(j-1)) + 1;
else
*(arr+i*lb+j) = max(*(arr+i*(lb-1)+(j)),*(arr+i*(lb)+(j-1)));
}
}
return *(arr+la*lb+lb);
}
int main()
{
char* a = (char *)malloc(size*sizeof(char));
scanf("%[^\n]%*c",a);
char* b = (char *)malloc(size*sizeof(char));
scanf("%[^\n]%*c",b);
printf("%d",strlen(a) + strlen(b) - (2 * find_subseq(a,b)));
return 0;
}
later I checked on a different compiler, it gives this error:
solution: malloc.c:2394: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
GDB trace:
Reading symbols from solution...done.
[New LWP 10243]
Core was generated by `solution'.
Program terminated with signal SIGABRT, Aborted.
#0 0x00007f622e4b2428 in __GI_raise (sig=sig@entry=6)
at ../sysdeps/unix/sysv/linux/raise.c:54
#0 0x00007f622e4b2428 in __GI_raise (sig=sig@entry=6)
at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007f622e4b402a in __GI_abort () at abort.c:89
#2 0x00007f622e4fa2e8 in __malloc_assert (
assertion=assertion@entry=0x7f622e60e190 "(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)",
file=file@entry=0x7f622e60abc5 "malloc.c", line=line@entry=2394,
function=function@entry=0x7f622e60e9d8 <__func__.11509> "sysmalloc")
at malloc.c:301
#3 0x00007f622e4fe426 in sysmalloc (nb=nb@entry=4112,
av=av@entry=0x7f622e841b20 <main_arena>) at malloc.c:2391
#4 0x00007f622e4ff743 in _int_malloc (
av=av@entry=0x7f622e841b20 <main_arena>, bytes=bytes@entry=4096)
at malloc.c:3827
#5 0x00007f622e501184 in __GI___libc_malloc (bytes=bytes@entry=4096)
at malloc.c:2913
#6 0x00007f622e4ea1d5 in __GI__IO_file_doallocate (
fp=0x7f622e842620 <_IO_2_1_stdout_>) at filedoalloc.c:127
#7 0x00007f622e4f8594 in __GI__IO_doallocbuf (
fp=fp@entry=0x7f622e842620 <_IO_2_1_stdout_>) at genops.c:398
#8 0x00007f622e4f78f8 in _IO_new_file_overflow (
f=0x7f622e842620 <_IO_2_1_stdout_>, ch=-1) at fileops.c:820
#9 0x00007f622e4f628d in _IO_new_file_xsputn (
f=0x7f622e842620 <_IO_2_1_stdout_>, data=0x7ffe22f98f77, n=1)
at fileops.c:1331
#10 0x00007f622e4cae00 in _IO_vfprintf_internal (
s=0x7f622e842620 <_IO_2_1_stdout_>, format=<optimized out>,
format@entry=0x4008dd "%zu", ap=ap@entry=0x7ffe22f98fc8)
at vfprintf.c:1631
#11 0x00007f622e5939ef in ___printf_chk (flag=flag@entry=1,
format=format@entry=0x4008dd "%zu") at printf_chk.c:35
#12 0x000000000040062b in printf (__fmt=0x4008dd "%zu")
at /usr/include/x86_64-linux-gnu/bits/stdio2.h:104
#13 main () at solution.c:56
What does this mean? Is this the reason for crash?