Magic numbers are unexplained values that often should be replaced with a named constant.
Questions tagged [magic-numbers]
193 questions
0
votes
1 answer
Check whether an user given number is a magic number or not
To me:
Magic Number: If sum of digits of a number becomes 1 until length of resultant becomes 1 is called magic number.
example: 1 [ sum: 1], 10 [sum: 1 + 0 = 1], 91 [sum: pass1: 9 + 1 = 10, pass2: 1 + 0 = 1], 100 [sum: 1 + 0 + 0 = 1] like…

Kunal Das
- 1
- 1
- 2
0
votes
2 answers
What to do with XML node names (hard coded values)?
I've been working with xml lately. And have noticed a bit of a phenomenon (maybe not that big of a deal to the rest of the world, but to me it was). Perhaps, it is me being a newb. But shouldn't most hard coded or magic numbers be broken out to a…

kevindaub
- 3,293
- 6
- 35
- 46
0
votes
1 answer
chrome extension - getting file type based on magic number
I need to write a chrome extension, that gets the downloaded file type.
This is the existing code that gets it by the extension file.
chrome.downloads.onDeterminingFilename.addListener(function(item, __suggest) {
function suggest(filename,…

Zag Gol
- 1,038
- 1
- 18
- 43
0
votes
1 answer
A magic number overkill
I have a piece of code in which I call a function with argument of a string value. The string value is taken from a string array using the index.
if (validateRejectionCategory(rejectionData[0])) {
......
}
In this case is 0 still considered a…

Belphegor21
- 454
- 1
- 5
- 24
0
votes
1 answer
How to differentiate .odt and .docx file apart from magic number and extension
I need to detect the document type of the given file. I did it using magic numbers for pdf,RTF, doc files. but whenever I tried to do the same on odt and docx files, unfortunately, I can't because the magic number for both are same. Please help me…

venkatesh karthick
- 335
- 3
- 12
0
votes
1 answer
Possible to used a named variable as multiple arguments?
I have some simple code:
context.drawImage(image, 0, 0);
I was wondering if it would be possible, using something like ES6 spread (edit: spread syntax, not 'spread operator') features, to eliminate the magic numbers and make the code more…

mikemaccana
- 110,530
- 99
- 389
- 494
0
votes
4 answers
Searching for a safe magic number for in-memory data structure
I'm implementing a heap allocator (malloc), and I need to choose a magic number to check if a given pointer point to a data structure I allocated. It seems obvious to me that no magic number can be considered completely safe (if the number is…

fokenrute
- 739
- 6
- 17
0
votes
0 answers
Bad magic number when deploying on Heroku
I am trying to deploy a Django app to Heroku which uses a client to connect to the api of an invoice service. Everything works when running localy, but when deploying on Heroku I get a Bad magic number errror:
error at /bexiopy/auth/
Bad magic…

syl-lo
- 123
- 1
- 1
- 5
0
votes
2 answers
Is it worth while creating a custom annotation to show that a method is simply helping readability?
Currently working with Spring and I've been learning about methods I can use to help the readability of my code, with one example being replace complicated conditionals with an easy to understand method call. For example:
private void myMethod(){
…

looksgoodhoss
- 31
- 5
0
votes
1 answer
Check if valid executable or shell file by checking magic number in C
The magic numbers that you will recognize are shown in the following table.
Name of file type Magic number (bytes) at start of file:
-Executable ASCII characters DEL, ‘E’, ‘L’ and ‘F’
-Shell script ASCII characters ‘#’ and ‘!’
Standard file…
user8477178
0
votes
2 answers
Weird SSE assembler instructions for double negation
GCC and Clang compilers seem to employ some dark magic. The C code just negates the value of a double, but the assembler instructions involve bit-wise XOR and the instruction pointer. Can somebody explain what is happening and why is it an optimal…

RuRo
- 311
- 4
- 17
0
votes
9 answers
Special IP addresses
In particular I'm looking for an IP address that I can put in my hosts file that will black-hole a given DNS name. Right now I'm using 127.0.0.1 but that would start acting odd if I installed any services.
How can I prevent a 3rd party program from…

BCS
- 75,627
- 68
- 187
- 294
0
votes
1 answer
Get the file size from a WebP file header
https://developers.google.com/speed/webp/docs/riff_container
I’ve got a WebP file (about 22 kilobytes), and the hexadecimal of the first 12 bytes is 524946461c57000057454250.
The first and last 4 bytes make sense (ASCII "RIFF" and "WEBP"), but I…

Eric Cochran
- 8,414
- 5
- 50
- 91
0
votes
0 answers
Minifilter - Reading file header
I'm using minifilter scanner program.
The flow of the process is as follow:
1. The program reads the file content with FltReadFile function and stores into Buffer.
2. The program sends the Buffer to user mode.
3. The user mode checks for file…

user3449011
- 37
- 5
0
votes
1 answer
Interleaving bzip2 and non-bzip2 data
I am looking at making a file format that interleaves two types of chunks of raw bytes.
One chunk will contain a block of bzip2-compressed data, which has a header containing the usual bzip2 magic number (BZh9).
The second chunk will consist of…

Alex Reynolds
- 95,983
- 54
- 240
- 345